Skip to content

Commit

Permalink
pre-commit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasDedieu committed Dec 17, 2024
1 parent 5a536a3 commit cb7d479
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion confit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ def from_cfg_str(cls, s: str, resolve: bool = False, registry: Any = None) -> An
@classmethod
def from_yaml_str(cls, s: str, resolve: bool = False, registry: Any = None) -> Any:
import yaml

class ConfitYamlLoader(yaml.SafeLoader):
def construct_object(self, x, deep=False):
if isinstance(x, yaml.ScalarNode):
if x.style == '"' or x.style == "'":
return loads(x.style+x.value+x.style)
return loads(x.style + x.value + x.style)
return loads(x.value)
return super().construct_object(x, deep)

Expand Down
2 changes: 1 addition & 1 deletion confit/utils/xjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def loads(s: str):
if set(s) & set(",'\"{}[]$"):
raise MalformedValueError(s)
return s


def dumps(o: Any):
"""
Expand Down
10 changes: 6 additions & 4 deletions tests/test_config_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,18 +699,20 @@ def test_very_long_yaml_config():


def test_escaped_string():
config = Config.from_yaml_str("""
test:
config = Config.from_yaml_str(
"""
test:
a: "1"
section:
num: 1
escaped_num: "1"
real_ref: ${test.a}
escaped_broken_ref: "${test.a"
escaped_ref: "${test.a}"
""").resolve(registry=registry)
"""
).resolve(registry=registry)
assert config["section"]["num"] == 1
assert config["section"]["escaped_num"] == "1"
assert config["section"]["real_ref"] == "1"
assert config["section"]["escaped_broken_ref"] == "${test.a"
assert config["section"]["escaped_ref"] == "${test.a}"
assert config["section"]["escaped_ref"] == "${test.a}"

0 comments on commit cb7d479

Please sign in to comment.