[New-bugs-announce] [issue36643] Forward reference is not resolved by dataclasses.fields()
Misha Drachuk
report at bugs.python.org
Tue Apr 16 15:44:38 EDT 2019
New submission from Misha Drachuk <misha at drach.uk>:
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]}
----------
components: Library (Lib)
messages: 340361
nosy: mdrachuk
priority: normal
severity: normal
status: open
title: Forward reference is not resolved by dataclasses.fields()
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36643>
_______________________________________
More information about the New-bugs-announce
mailing list