Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several minor fixes #11

Merged
merged 2 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
run: pip install poetry
- name: Install Dependencies
run: poetry install
- name: Run tests
Expand Down
4 changes: 3 additions & 1 deletion runtype/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class RuntypeError(TypeError):


class TypeMismatchError(RuntypeError):
pass
def __str__(self) -> str:
v, t = self.args
return f"Expected type '{t}', but got value: {v}."



Expand Down
2 changes: 1 addition & 1 deletion runtype/pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProductType(base_types.ProductType, PythonType):
"""
def validate_instance(self, obj, sampler=None):
if not isinstance(obj, tuple):
raise TypeMismatchError(f"Expected a tuple. Got {type(obj)}")
raise TypeMismatchError(obj, tuple)
if self.types and len(obj) != len(self.types):
raise LengthMismatchError(self, obj)
for type_, item in zip(self.types, obj):
Expand Down
4 changes: 2 additions & 2 deletions runtype/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def assert_isa(obj, t):
ensure_isa(obj, t)
except TypeMismatchError as e:
item_value, item_type = e.args
msg = f"Expected value of type {t}, instead got {obj!r}"
msg = f"Expected value of type '{t}', instead got '{obj!r}'."
if item_value is not obj:
msg += f'\n\n Failed on item: {item_value!r}, expected type {item_type}'
msg += f"\n\n Failed on item: '{item_value!r}', expected type '{item_type}'."
raise TypeError(msg)


Expand Down