Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if cls.__origin__ == list:
try:
converter = map_type(cls.__args__[0])
except TypeError as e:
if '~T' in str(e):
e = TypeError(f"Type is required with 'List' annotation")
raise e from None
else:
converter = List.subclass(converter)
if cls.__origin__ == dict:
log.warn("Schema enforcement not possible with 'Dict' annotation")
key = map_type(cls.__args__[0])
value = map_type(cls.__args__[1])
converter = Dictionary.subclass(key, value)
elif cls.__origin__ == Union:
converter = map_type(cls.__args__[0])
assert len(cls.__args__) == 2
assert cls.__args__[1] == type(None)
converter = converter.as_optional()
if converter:
log.debug(f'Mapped {cls!r} to new converter: {converter}')
return converter
raise TypeError(f'Unsupported container type: {cls.__origin__}')
else:
for converter in Converter.__subclasses__():
if converter.TYPE == cls: