admin管理员组文章数量:1417411
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.
本文标签: pycharmPython inspector ignores property return hint when using TypeVarStack Overflow
版权声明:本文标题:pycharm - Python inspector ignores property return hint when using TypeVar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745264111a2650492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论