Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
Merge branch 'fix-dumper-compat' into v2_main
Browse files Browse the repository at this point in the history
  • Loading branch information
boonhapus committed Aug 10, 2024
2 parents e9bec6c + 91e7a02 commit c416d92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/thoughtspot_tml/_compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import sys

import yaml


try:
Dumper = yaml.CDumper
Loader = yaml.CSafeLoader
except AttributeError:
Dumper = yaml.Dumper
Loader = yaml.SafeLoader

if sys.version_info < (3, 8):
from typing_extensions import get_origin, get_args
from typing_extensions import Literal, TypedDict
Expand Down
2 changes: 1 addition & 1 deletion src/thoughtspot_tml/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.0"
__version__ = "2.1.1"
8 changes: 5 additions & 3 deletions src/thoughtspot_tml/_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import yaml

from thoughtspot_tml import _compat

NEARLY_INFINITY = 999999999 # This used to be math.inf, but C has no concept of infinity. ;)

# TML column ids typically take the form..
Expand Down Expand Up @@ -60,7 +62,7 @@ def _double_quote_when_special_char(dumper: yaml.Dumper, data: str) -> yaml.Scal
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style=style)


yaml.add_representer(str, _double_quote_when_special_char, Dumper=yaml.CDumper)
yaml.add_representer(str, _double_quote_when_special_char, Dumper=_compat.Dumper)

# BUG: pyyaml #89 ==> resolved by #635
yaml.Loader.yaml_implicit_resolvers.pop("=")
Expand All @@ -70,7 +72,7 @@ def load(document: str) -> Dict[str, Any]:
"""
Load a TML object.
"""
return yaml.load(document, Loader=yaml.CSafeLoader)
return yaml.load(document, Loader=_compat.Loader)


def dump(document: Dict[str, Any]) -> str:
Expand All @@ -92,6 +94,6 @@ def dump(document: Dict[str, Any]) -> str:
"default_flow_style": False,
"sort_keys": False,
"allow_unicode": True,
"Dumper": yaml.CDumper,
"Dumper": _compat.Dumper,
}
return yaml.dump(document, **options)

0 comments on commit c416d92

Please sign in to comment.