linter problem
I have a module with something like the following code:
# my_module.py
@dataclass(frozen=True)
class MyClass:
field_1: float
field_2: float
field_3: Optional[list[float]] = None
def my_function() -> MyClass:
# Do some stuff
return MyClass(1.0, 2.0, field_3=[1, 2, 3])
I have a test:
# my_test.py
def test_my_function():
my_class = my_function()
assert my_class.field_1 == 1.0
assert my_class.field_2 == 2.0
assert all(a == e for a, e in zip(my_class.field_3, [1, 2, 3]))
# All of the assert statements issue the following warning:
# Unresolved attribute reference 'field_X' for class or class '(MyClass, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any, Any)'
At some point I hand initially defined MyClass
as a collections.namedtuple
. I changed my mind and switched to a typing.NamedTuple
for type support. I was getting the same warnings with typing.NamedTuple
, so I thought I'd try using a @dataclass
to resolve the warnings. It sort of seems like PyCharm still thinks its a collections.namedtuple
with the wrong set of attributes.
I have tried running File > Repair IDE
several times, but I continue to get the warning. Is there anything else I can do?
请先登录再写评论。