Pycharm自动完成不适用于带边界的TypeVar

2024-04-26 07:07:02 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在Pycharm中使用带边界的TypeVar时,没有与TypeVar的上限相关的提示。示例:

from typing import TypeVar

class TestClass:

    def test_class_method(self):
        print("test")

T = TypeVar('T', bound=TestClass)

def test_method(test_class: T):
    test_class.test_class_method()

test_method(TestClass())

在这里,我希望当我在test_class上按ctrl+space时,test_class method会在自动完成中列出。但什么都没有。当我突出显示test_class时,有一个正确的工具提示:推断类型:TypeVar('T',TestClass)。我这边有错误吗,还是自动完成的问题?在


Tags: fromtestimportself示例typingdefmethod