Skip to content

Commit

Permalink
[#50] Fix: delegate hyphen handling to pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanofusai committed Dec 17, 2024
1 parent ee012d0 commit a3f8733
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ database:
user: $DATABASE_USER
timeout: $DATABASE_TIMEOUT?
environment: development
is-debug: true
is_debug: true
```
`config.py`
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pyamldantic"
version = "1.1.0"
version = "1.2.0"
description = "Validate and serialize YAML config files with Pydantic, with support for environment variables."
readme = "README.md"
authors = [
Expand Down
18 changes: 0 additions & 18 deletions src/pyamldantic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def load(cls, path: str, *, schema: type[T]) -> T:
except ScannerError as e:
raise InvalidYAMLError(path, e) from None

cls._normalize_keys(data)
cls._set_env_vars(data)

try:
Expand All @@ -58,23 +57,6 @@ def load(cls, path: str, *, schema: type[T]) -> T:

# Private methods

@classmethod
def _normalize_keys(cls, data: dict[str, Any]) -> None:
"""
Replace dashes in keys with underscores.
:param data: The data to process
:type data: dict[str, Any]
"""
for k in list(data.keys()):
new_key = k.replace("-", "_")

if new_key != k:
data[new_key] = data.pop(k)

if isinstance(data[new_key], dict):
cls._normalize_keys(data[new_key])

@classmethod
def _set_env_vars(cls, data: dict[str, Any]) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ database:
user: $DATABASE_USER
timeout: $DATABASE_TIMEOUT?
environment: testing
is-debug: true
is_debug: true
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3f8733

Please sign in to comment.