Skip to content

Commit

Permalink
fix: don't modify by injecting defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Oct 16, 2024
1 parent c0af833 commit d71c706
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/validate_pyproject/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def formats(self) -> Mapping[str, FormatValidationFn]:
def generated_code(self) -> str:
if self._code_cache is None:
fmts = dict(self.formats)
self._code_cache = FJS.compile_to_code(self.schema, self.handlers, fmts)
self._code_cache = FJS.compile_to_code(
self.schema, self.handlers, fmts, use_default=False
)

return self._code_cache

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

Expand Down
3 changes: 3 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import logging
from pathlib import Path

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

toml_equivalent = tomllib.loads(example.read_text())
copy_toml = copy.deepcopy(toml_equivalent)
validator = api.Validator(extra_plugins=load_tools)
assert validator(toml_equivalent) is not None
assert toml_equivalent == copy_toml


def test_examples_cli(example: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pre_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .helpers import error_file, get_tools, get_tools_as_args

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


def _pre_compile_checks(path: Path):
Expand Down

0 comments on commit d71c706

Please sign in to comment.