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

dataclass: Test is_a before calling cast. #13

Merged
merged 2 commits into from
Dec 15, 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 @@ -3,7 +3,7 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04 # See https://github.com/actions/setup-python/issues/544
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0-rc - 3.10, pypy3]
Expand Down
6 changes: 5 additions & 1 deletion runtype/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def _validate_attr(config, should_cast, sampler, obj, name, type_, value):
try:
if should_cast: # Basic cast
assert not sampler
return config.cast(value, type_)
try:
config.ensure_isa(value, type_, sampler)
return value
except TypeMismatchError:
return config.cast(value, type_)
else:
config.ensure_isa(value, type_, sampler)
except TypeMismatchError as e:
Expand Down