Skip to content

Commit

Permalink
Stop modifying behavior of yaml on load (#1826)
Browse files Browse the repository at this point in the history
* Stop modifying behavior of yaml on load

Only modify a copy of ``SafeLoader`` to ensure that we don't change the behaviour of ``pyyaml`` for everyone.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update util.py

Try to address the CodeQL warning.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Non-functional commit to trigger the github worklow checks hoping that the codecov isue is resolved.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Koudai Aono <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent b4d6bf7 commit 480779e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions datamodel_code_generator/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import copy
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Dict, TypeVar

Expand Down Expand Up @@ -69,9 +70,13 @@ def load_toml(path: Path) -> Dict[str, Any]:
return toml.load(path)


SafeLoader.yaml_constructors[
'tag:yaml.org,2002:timestamp'
] = SafeLoader.yaml_constructors['tag:yaml.org,2002:str']
SafeLoaderTemp = copy.deepcopy(SafeLoader)
SafeLoaderTemp.yaml_constructors = copy.deepcopy(SafeLoader.yaml_constructors)
SafeLoaderTemp.add_constructor(
'tag:yaml.org,2002:timestamp',
SafeLoaderTemp.yaml_constructors['tag:yaml.org,2002:str'],
)
SafeLoader = SafeLoaderTemp

Model = TypeVar('Model', bound=_BaseModel)

Expand Down

0 comments on commit 480779e

Please sign in to comment.