python - pylint 为可调用的对象属性给出不可调用的错误

标签 python pylint type-hinting

不确定是我做错了什么还是 pylint 有问题。在下面的代码中,我得到了 self.type is not callable E1102 的 linting 错误。

虽然我可以忽略它并继续工作,但似乎这种事情应该很容易修复......只是不知道如何修复它。

from typing import Callable


class Thing:
    def __init__(self, thing_type: Callable):
        self._type = thing_type
        self._value = None

    @property
    def type(self) -> Callable:
        return self._type

    @property
    def value(self):
        return self._value

    @value.setter
    def value(self, value):
        self._value = self.type(value)

enter image description here

最佳答案

暂时不接受这个答案,但我确实发现它与 @property 装饰器的使用有关。在创建新的对象属性的过程中,类型提示信息丢失到pylint,VSCode intellisense似乎不起作用。使用旧式属性语法,我得到了正确的 linting 和类型提示(见下图)

看起来有点遗憾,但我希望有人能提出更好的答案

enter image description here

关于python - pylint 为可调用的对象属性给出不可调用的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53598374/

相关文章:

python - LearnPython.org 生成器问题

python - 如何告诉 pylint 组合类的子类可以访问父成员?

python - 为什么 Pylint 反对单字符变量名?

PhpStorm 没有将返回类型识别为另一个的扩展

python - mitmproxy 将请求重定向到本地主机并设置主机 header

python - 如何在 Python 中使用 -p 选项运行 os.mkdir()?

python - 在绘图条形图中更改颜色

pyqt4 - Sublime Pylint PyQt4 模块没有成员

Python 类型提示 : What does Callable followed by a TypeVar mean?

java - 在 Clojure 中为 Java 返回值使用类型提示