This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mdrachuk
Recipients mdrachuk
Date 2019-04-16.19:44:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555443878.01.0.308772794144.issue36643@roundup.psfhosted.org>
In-reply-to
Content
Forward reference is not resolved by `dataclasses.fields()`, but it works with `typing.get_type_hints()`.

E.g. 

from dataclasses import dataclass, fields
from typing import Optional, get_type_hints

@dataclass
class Nestable:
    child: Optional['Nestable']

o = Nestable(None)
print('fields:', fields(o))
print('type hints:', get_type_hints(Nestable))

... outputs the following:
 
fields: (Field(name='child',type=typing.Union[ForwardRef('Nestable'), NoneType] ... )
type hints: {'child': typing.Union[__main__.Nestable, NoneType]}
History
Date User Action Args
2019-04-16 19:44:38mdrachuksetrecipients: + mdrachuk
2019-04-16 19:44:38mdrachuksetmessageid: <1555443878.01.0.308772794144.issue36643@roundup.psfhosted.org>
2019-04-16 19:44:37mdrachuklinkissue36643 messages
2019-04-16 19:44:37mdrachukcreate