Closed AlirezaRoshanzamir closed 4 years ago
Thanks, I'm glad you like it. You may also like https://github.com/pwwang/python-varname by @pwwang.
This has nothing to do with nameof. The attribute just doesn't exist, nothing nameof can help with, it doesn't even get called.
from dataclasses import dataclass, field
from typing import List
@dataclass
class Foo:
bar: List[int] = field(default_factory=lambda: [])
print(Foo.bar)
This just seems to be how dataclasses work. default_factory=lambda: []
doesn't seem relevant.
You can still use the attribute on instances though:
print(nameof(Foo().bar)) # bar
Hello, First of all, thanks for the great useful library.
It seems that there is a problem with the dataclass attributes that have a field default value.
The above code raises:
AttributeError: type object 'Foo' has no attribute 'bar'