Skip to content

Commit

Permalink
Make fields private, fix tox
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI committed Nov 11, 2023
1 parent a24f957 commit 7268fab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ deps = flake8
commands = flake8 --doctests setup.py voluptuous

[testenv:mypy]
deps = mypy pytest
deps =
mypy
pytest
commands = mypy voluptuous
10 changes: 5 additions & 5 deletions voluptuous/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Invalid(Error):

def __init__(self, message: str, path: typing.Optional[typing.List[str]] = None, error_message: typing.Optional[str] = None, error_type: typing.Optional[str] = None) -> None:
Error.__init__(self, message)
self.path_value = path or []
self.error_message_value = error_message or message
self._path = path or []
self._error_message = error_message or message
self.error_type = error_type

@property
Expand All @@ -31,11 +31,11 @@ def msg(self) -> str:

@property
def path(self) -> typing.List[str]:
return self.path_value
return self._path

@property
def error_message(self) -> str:
return self.error_message_value
return self._error_message

def __str__(self) -> str:
path = ' @ data[%s]' % ']['.join(map(repr, self.path)) \
Expand All @@ -46,7 +46,7 @@ def __str__(self) -> str:
return output + path

def prepend(self, path: typing.List[str]) -> None:
self.path_value = path + self.path_value
self._path = path + self.path


class MultipleInvalid(Invalid):
Expand Down
5 changes: 2 additions & 3 deletions voluptuous/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,7 @@ def extend(self, schema: Schemable, required: typing.Optional[bool] = None, extr
:param extra: if set, overrides `extra` of this `Schema`
"""

assert type(self.schema) == dict and type(schema) == dict, 'Both schemas must be dictionary-based'
assert isinstance(self.schema, dict)
assert isinstance(self.schema, dict) and isinstance(schema, dict), 'Both schemas must be dictionary-based'

result = self.schema.copy()

Expand All @@ -779,7 +778,7 @@ def key_literal(key):

# if both are dictionaries, we need to extend recursively
# create the new extended sub schema, then remove the old key and add the new one
if type(result_value) == dict and type(value) == dict:
if isinstance(result_value, dict) and isinstance(value, dict):
new_value = Schema(result_value).extend(value).schema
del result[result_key]
result[key] = new_value
Expand Down
6 changes: 3 additions & 3 deletions voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_literal():
except MultipleInvalid as e:
assert str(e) == "{'b': 1} not match for {'a': 1}"
assert len(e.errors) == 1
assert type(e.errors[0]) == LiteralInvalid
assert isinstance(e.errors[0], LiteralInvalid)
else:
assert False, "Did not raise Invalid"

Expand All @@ -184,7 +184,7 @@ class C1(object):
except MultipleInvalid as e:
assert str(e) == "expected C1"
assert len(e.errors) == 1
assert type(e.errors[0]) == TypeInvalid
assert isinstance(e.errors[0], TypeInvalid)
else:
assert False, "Did not raise Invalid"

Expand All @@ -200,7 +200,7 @@ class C2:
except MultipleInvalid as e:
assert str(e) == "expected C2"
assert len(e.errors) == 1
assert type(e.errors[0]) == TypeInvalid
assert isinstance(e.errors[0], TypeInvalid)
else:
assert False, "Did not raise Invalid"

Expand Down

0 comments on commit 7268fab

Please sign in to comment.