Vin*_* W. 7 python pylint type-hinting
不确定我是否做错了什么或者这是否是一个问题pylint。在下面的代码中,我收到一个self.type无法调用的linting 错误E1102。
虽然我可以忽略它并继续工作,但似乎这种事情应该很容易解决......只是不知道如何解决它。
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)
Run Code Online (Sandbox Code Playgroud)
暂时不会接受这个答案,但我确实发现它与 @property 装饰器的使用有关。在创建新对象属性的过程中,类型提示信息丢失给 pylint,并且 VSCode intellisense 似乎不起作用。使用旧式属性语法,我得到了正确的 linting 和类型提示(见下图)
看起来有点可惜,但我希望有人能给出更好的答案
| 归档时间: |
|
| 查看次数: |
12661 次 |
| 最近记录: |