From 02f1153eccf40f88ce0e64d8e09ab7275504b003 Mon Sep 17 00:00:00 2001 From: Maximilian Sander <55374514+maximilian-tech@users.noreply.github.com> Date: Sat, 11 May 2024 18:49:41 +0200 Subject: [PATCH 1/2] Extend parsing of Scientific Notation to JSON capabilites --- datamodel_code_generator/util.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/datamodel_code_generator/util.py b/datamodel_code_generator/util.py index b00b2231e..5235f4c6f 100644 --- a/datamodel_code_generator/util.py +++ b/datamodel_code_generator/util.py @@ -2,6 +2,7 @@ import copy from pathlib import Path +import re from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar import pydantic @@ -75,6 +76,17 @@ 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( + u'tag:yaml.org,2002:float', + re.compile(u'''^(?: + [-+]?(?:[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(u'-+0123456789.') +) SafeLoader = SafeLoaderTemp Model = TypeVar('Model', bound=_BaseModel) From 99a0eb9e0ee13fc5ef304e17bd62536edb6cea9c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 17:03:23 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- datamodel_code_generator/util.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/datamodel_code_generator/util.py b/datamodel_code_generator/util.py index 5235f4c6f..9818cb501 100644 --- a/datamodel_code_generator/util.py +++ b/datamodel_code_generator/util.py @@ -1,8 +1,8 @@ from __future__ import annotations import copy -from pathlib import Path import re +from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar import pydantic @@ -77,15 +77,18 @@ def load_toml(path: Path) -> Dict[str, Any]: SafeLoaderTemp.yaml_constructors['tag:yaml.org,2002:str'], ) SafeLoaderTemp.add_implicit_resolver( - u'tag:yaml.org,2002:float', - re.compile(u'''^(?: + '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(u'-+0123456789.') + |\\.(?:nan|NaN|NAN))$""", + re.X, + ), + list('-+0123456789.'), ) SafeLoader = SafeLoaderTemp