最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python typing - PyCharm type hinting for generic type concludes property instead of property's return type - Stack Overf

programmeradmin1浏览0评论

I have a problem with type hints recognition in Pycharm. Following simplified example constructed to show my issue:

class A:
    @property
    def a(self) -> A:
        a_ = ...
        return a_

def f[T: A](b: T):
    c = b.a  # `b.a` recognized as type `property` instead of `A` 

The variable c is not recognized as having type A (which is returned by the property). Instead it is recognized as having type property.

Any suggestion whether I do something wrong, or need a workaround, possibly because of known(?) PyCharm limitation in PEP 695 handling? I use Python 3.12.

Note this is not exactly same case as with TypeVar. If I use TypeVar construction, then Pycharm makes an Any from a.b and then thus stops complaining about the type being a property instead of what it really "returns".

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论