Skip to content

Commit 38403cf

Browse files
authored
fix: don't modify by injecting defaults (#213)
2 parents c0af833 + d71c706 commit 38403cf

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/validate_pyproject/api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ def formats(self) -> Mapping[str, FormatValidationFn]:
246246
def generated_code(self) -> str:
247247
if self._code_cache is None:
248248
fmts = dict(self.formats)
249-
self._code_cache = FJS.compile_to_code(self.schema, self.handlers, fmts)
249+
self._code_cache = FJS.compile_to_code(
250+
self.schema, self.handlers, fmts, use_default=False
251+
)
250252

251253
return self._code_cache
252254

@@ -259,7 +261,9 @@ def __call__(self, pyproject: T) -> T:
259261
and raises an exception when it is not a valid.
260262
"""
261263
if self._cache is None:
262-
compiled = FJS.compile(self.schema, self.handlers, dict(self.formats))
264+
compiled = FJS.compile(
265+
self.schema, self.handlers, dict(self.formats), use_default=False
266+
)
263267
fn = partial(compiled, custom_formats=self._format_validators)
264268
self._cache = typing.cast(ValidationFn, fn)
265269

tests/test_examples.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import logging
23
from pathlib import Path
34

@@ -14,8 +15,10 @@ def test_examples_api(example: Path) -> None:
1415
load_tools = get_tools(example)
1516

1617
toml_equivalent = tomllib.loads(example.read_text())
18+
copy_toml = copy.deepcopy(toml_equivalent)
1719
validator = api.Validator(extra_plugins=load_tools)
1820
assert validator(toml_equivalent) is not None
21+
assert toml_equivalent == copy_toml
1922

2023

2124
def test_examples_cli(example: Path) -> None:

tests/test_pre_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .helpers import error_file, get_tools, get_tools_as_args
1717

18-
MAIN_FILE = "hello_world.py" # Let's use something different that `__init__.py`
18+
MAIN_FILE = "hello_world.py" # Let's use something different than `__init__.py`
1919

2020

2121
def _pre_compile_checks(path: Path):

0 commit comments

Comments
 (0)