pylint 为可调用的对象属性给出不可调用错误 [英] pylint giving not-callable error for object property that is callable

查看:46
本文介绍了pylint 为可调用的对象属性给出不可调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定是我做错了什么还是pylint 有问题.在下面的代码中,我收到一个 linting 错误,即 self.type 不可调用 E1102.

Not sure if I am doing something wrong or if this is a problem with pylint. In the code below I get a linting error that self.type is not callable E1102.

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

Although I could just ignore it and keep working, seems like this kind of thing should be easy to fix... just can't figure out how to fix it.

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)

推荐答案

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

Will leave this answer unaccepted for awhile, but I did figure out that it has something to do with the use of the @property decorator. In the process of creating the new object property, the type hint information is lost to pylint, and VSCode intellisense doesn't seem to work. Using the old style property syntax I get proper linting and type hinting (see image below)

看起来有点丢人,但我希望有人想出更好的答案

Seems a bit of a shame, but am hoping someone comes up with a better answer

这篇关于pylint 为可调用的对象属性给出不可调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆