Oct-22-2020, 03:26 AM
(This post was last modified: Oct-22-2020, 03:30 AM by Cyril.
Edit Reason: Fix formatting
)
Hi,
When I create a dataclass with same field.name and field.type and assign a default value to None typehint get lost. I know that it does not respect naming convention but I have reasons to do so in my particular case.
Standard Behaviour
When I create a dataclass with same field.name and field.type and assign a default value to None typehint get lost. I know that it does not respect naming convention but I have reasons to do so in my particular case.
Standard Behaviour
from dataclasses import dataclass import typing from typing import Optional, List, Tuple @dataclass class NotBuiltIn: test: str @dataclass class MyDataClass: field: Optional[NotBuiltIn] = None typing.get_type_hints(MyDataClass)
Output:{'field': typing.Union[__main__.NotBuiltIn, NoneType]}
Type hint get lost (variable name == type name) :@dataclass class layers: ... @dataclass class material: layers: Optional[layers] = None typing.get_type_hints(material)
Output:{'layers': NoneType}
It looks like a bug but is it ?