Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_simple_dump_and_load_dataclass(self):
class C:
pass
hints = get_type_hints(C.__init__)
self.assertDictEqual({}, hints)
def _get_attributes_and_types(cls: type,
strict: bool) -> Dict[str, Optional[type]]:
if '__slots__' in cls.__dict__:
attributes = {attr: None for attr in cls.__slots__}
elif hasattr(cls, '__annotations__'):
# Fixme: remove code below if tests succeed on all platforms.
# attributes = cls.__annotations__
attributes = get_type_hints(cls)
elif strict:
hints = get_type_hints(cls.__init__)
attributes = {k: hints[k] for k in hints if k != 'self'}
else:
attributes = {}
# Add properties and class variables.
props, class_vars = _get_class_props(cls)
for elem in props + class_vars:
attributes[elem] = None
return attributes
def _get_constructor_args(
obj,
cls,
meta_hints,
attr_getters=None,
**kwargs) -> dict:
# Loop through the signature of cls: the type we try to deserialize to. For
# every required parameter, we try to get the corresponding value from
# json_obj.
signature_parameters = _get_signature(cls)
hints = get_type_hints(cls.__init__)
attr_getters = dict(**(attr_getters or {}))
result = {}
for sig_key, sig in signature_parameters.items():
if sig_key != 'self':
key, value = _get_value_for_attr(obj=obj,
orig_cls=cls,
meta_hints=meta_hints,
attr_getters=attr_getters,
sig_key=sig_key,
cls=hints.get(sig_key, None),
sig=sig,
**kwargs)
if key:
result[key] = value
return result
def _get_attributes_and_types(cls: type,
strict: bool) -> Dict[str, Optional[type]]:
if '__slots__' in cls.__dict__:
attributes = {attr: None for attr in cls.__slots__}
elif hasattr(cls, '__annotations__'):
# Fixme: remove code below if tests succeed on all platforms.
# attributes = cls.__annotations__
attributes = get_type_hints(cls)
elif strict:
hints = get_type_hints(cls.__init__)
attributes = {k: hints[k] for k in hints if k != 'self'}
else:
attributes = {}
# Add properties and class variables.
props, class_vars = _get_class_props(cls)
for elem in props + class_vars:
attributes[elem] = None
return attributes