You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Disclaimer : This might be a cattrs issue (please let me know if I should close this and repost there).
Raising here since after my limited investigation it seems like it might be solvable within _funcs.py (might break other things). Per my understanding, the issue primarily stems from PEP 563. So the behavior changes based on if you use from __future__ import annotations in your code.
from __future__ importannotations# comment this line and rerun for successfromdataclassesimportdataclassfromcattrimportstructure@dataclassclassFoo:
bar: intprint(structure({"bar": 123}, Foo))
Return the tuple of ``attrs`` attributes for a class.
The tuple also allows accessing the fields by their names (see below for
examples).
:param type cls: Class to introspect.
:raise TypeError: If *cls* is not a class.
:raise attr.exceptions.NotAnAttrsClassError: If *cls* is not an ``attrs``
class.
:rtype: tuple (with name accessors) of `attrs.Attribute`
.. versionchanged:: 16.2.0 Returned tuple allows accessing the fields
by name.
"""
ifnotisclass(cls):
raiseTypeError("Passed object must be a class.")
attrs=getattr(cls, "__attrs_attrs__", None)
ifattrsisNone:
raiseNotAnAttrsClassError(
"{cls!r} is not an attrs-decorated class.".format(cls=cls)
)
returnattrs
To me it seems like the fields in step 2 and 4 could/should be the same? I might be missing context, happy to work on this given some general guidance.
Thank you for the two powerful libraries!
The text was updated successfully, but these errors were encountered:
@euresti dataclasses was intentional, opened the issue in attr since seemed like a generic solution might belong in attr but seems like its being taken care of in cattrs.
Disclaimer : This might be a cattrs issue (please let me know if I should close this and repost there).
Raising here since after my limited investigation it seems like it might be solvable within
_funcs.py
(might break other things). Per my understanding, the issue primarily stems from PEP 563. So the behavior changes based on if you usefrom __future__ import annotations
in your code.This seems to be the code flow
gen_structure_attrs_fromdict
is called https://github.com/python-attrs/cattrs/blob/20ca64405944ea81ac207e070e180d2d805c8fd1/src/cattr/converters.py#L730-L734fields
in_compat.py
incattr
. Thisfields
works as expected. https://github.com/python-attrs/cattrs/blob/20ca64405944ea81ac207e070e180d2d805c8fd1/src/cattr/_compat.py#L49-L56if isisntance(field, str)
thenresolve_types
is called in_funcs.py
in attr.attrs/src/attr/_funcs.py
Line 413 in 3df7bbe
resolve_types
calls thefields
in_make.py
which raisesNotAnAttrsClassError
attrs/src/attr/_make.py
Lines 2029 to 2054 in 3df7bbe
To me it seems like the fields in step 2 and 4 could/should be the same? I might be missing context, happy to work on this given some general guidance.
Thank you for the two powerful libraries!
The text was updated successfully, but these errors were encountered: