Skip to content

Commit a98a5a8

Browse files
authored
Merge pull request #11 from erezsh/oct9
Several minor fixes
2 parents a5fec56 + 848f342 commit a98a5a8

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
python-version: ${{ matrix.python-version }}
1717
- name: Install Poetry
18-
uses: snok/install-poetry@v1
18+
run: pip install poetry
1919
- name: Install Dependencies
2020
run: poetry install
2121
- name: Run tests

runtype/base_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class RuntypeError(TypeError):
1515

1616

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

2022

2123

runtype/pytypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ProductType(base_types.ProductType, PythonType):
5656
"""
5757
def validate_instance(self, obj, sampler=None):
5858
if not isinstance(obj, tuple):
59-
raise TypeMismatchError(f"Expected a tuple. Got {type(obj)}")
59+
raise TypeMismatchError(obj, tuple)
6060
if self.types and len(obj) != len(self.types):
6161
raise LengthMismatchError(self, obj)
6262
for type_, item in zip(self.types, obj):

runtype/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def assert_isa(obj, t):
4747
ensure_isa(obj, t)
4848
except TypeMismatchError as e:
4949
item_value, item_type = e.args
50-
msg = f"Expected value of type {t}, instead got {obj!r}"
50+
msg = f"Expected value of type '{t}', instead got '{obj!r}'."
5151
if item_value is not obj:
52-
msg += f'\n\n Failed on item: {item_value!r}, expected type {item_type}'
52+
msg += f"\n\n Failed on item: '{item_value!r}', expected type '{item_type}'."
5353
raise TypeError(msg)
5454

5555

0 commit comments

Comments
 (0)