Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend parsing of Scientific Notation to JSON capabilites #1956

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
15 changes: 15 additions & 0 deletions datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import copy
import re
from functools import cached_property # noqa: F401
from pathlib import Path
from typing import ( # noqa: F401
Expand Down Expand Up @@ -56,6 +57,20 @@ def load_toml(path: Path) -> Dict[str, Any]:
'tag:yaml.org,2002:timestamp',
SafeLoaderTemp.yaml_constructors['tag:yaml.org,2002:str'],
)
SafeLoaderTemp.add_implicit_resolver(
'tag:yaml.org,2002:float',
re.compile(
"""^(?:
[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
|\\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
|[-+]?\\.(?:inf|Inf|INF)
|\\.(?:nan|NaN|NAN))$""",
re.X,
),
list('-+0123456789.'),
)
SafeLoader = SafeLoaderTemp

Model = TypeVar('Model', bound=_BaseModel)
Expand Down
Loading