我在python 3中有以下代码:
class Position:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
def __add__(self, other: Position) -> Position:
return Position(self.x + other.x, self.y + other.y)
Run Code Online (Sandbox Code Playgroud)
但是我的编辑器(PyCharm)说无法解析引用位置(在_add__方法中).我该如何指定我希望返回类型是类型__add__?
编辑:我认为这实际上是一个PyCharm问题.它实际上使用其警告中的信息和代码完成

但如果我错了,请纠正我,并需要使用其他语法.
在Python中,前缀为一个下划线表示不应在其类之外访问成员.这似乎是基于Java和C++的每个类.
但是,pylint似乎在每个对象的基础上强制执行此约定.有没有办法允许每个类访问而不诉诸#pylint: disable=protected-access?
class A:
def __init__(self):
self._b = 5
def __eq__(self, other):
return self._b == other._b
Run Code Online (Sandbox Code Playgroud)
结果:
pylint a.py
a.py:6: W0212(protected-access) Access to a protected member _b of a client class
Run Code Online (Sandbox Code Playgroud)
Pylint在这里描述了这条消息.