Message340361
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]} |
|
Date |
User |
Action |
Args |
2019-04-16 19:44:38 | mdrachuk | set | recipients:
+ mdrachuk |
2019-04-16 19:44:38 | mdrachuk | set | messageid: <1555443878.01.0.308772794144.issue36643@roundup.psfhosted.org> |
2019-04-16 19:44:37 | mdrachuk | link | issue36643 messages |
2019-04-16 19:44:37 | mdrachuk | create | |
|