Skip to content

Commit

Permalink
Merge pull request #13 from erezsh/dec12
Browse files Browse the repository at this point in the history
dataclass: Test is_a before calling cast.
  • Loading branch information
erezsh authored Dec 15, 2022
2 parents 115d901 + ea1cbbb commit 1a689cc
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit 1a689cc

Please sign in to comment.