Skip to content

Commit

Permalink
support tuple of types
Browse files Browse the repository at this point in the history
  • Loading branch information
jmosbacher committed Jul 10, 2023
1 parent 93de8ca commit dbf6991
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions straxen/url_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,18 @@ def validate_type(self, value):
# its validation is more flexible than isinstance
# it will coerce standard equivalent types
cfg = get_config(dict(arbitrary_types_allowed=True))

for validator in find_validators(self.final_type, config=cfg):
if isinstance(self.final_type, tuple):
validators = [ v for t in self.final_type for v in find_validators(t, config=cfg)]
else:
validators = find_validators(self.final_type, config=cfg)
for validator in validators:
try:
value = validator(value)
validator(value)
break
except:
pass

assert isinstance(value, self.final_type), msg
else:
raise TypeError(msg)

return value

Expand Down

0 comments on commit dbf6991

Please sign in to comment.