from abc import ABC, abstractmethod
from typing import TypeVar
T = TypeVar('T', bound='Abs')
class A:
val: int = 10
class Abs(ABC):
@property
@abstractmethod
def a(self) -> A:
...
class MyClass(Abs):
_a: A = A()
@property
def a(self) -> A:
return self._a
def foo(obj: T):
print(obj.a.val)
In this example the code inspector highlights obj.a.val
with Unresolved attribute reference 'val' for class 'property'
.
Is that me incorrectly using the TypeVar, or maybe the problem is with PyCharm inspector?
Is it possible in the first place to infer that a
has val
for sure?
from abc import ABC, abstractmethod
from typing import TypeVar
T = TypeVar('T', bound='Abs')
class A:
val: int = 10
class Abs(ABC):
@property
@abstractmethod
def a(self) -> A:
...
class MyClass(Abs):
_a: A = A()
@property
def a(self) -> A:
return self._a
def foo(obj: T):
print(obj.a.val)
In this example the code inspector highlights obj.a.val
with Unresolved attribute reference 'val' for class 'property'
.
Is that me incorrectly using the TypeVar, or maybe the problem is with PyCharm inspector?
Is it possible in the first place to infer that a
has val
for sure?
1 Answer
Reset to default 1Your code is fine. The inspector is handling it wrong. mypy accepts your code without complaint, and your code behaves correctly at runtime too.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745264112a4619347.html
评论列表(0条)