我收到来自PyCharm的有关未解决的引用的警告。 这是代码结构相似,并且也应该收到警告。Docstring中未解决的引用警告 - Python 3.6 - Pycharm 17.1.4
class Parent:
"""
=== Attributes ===
@type public_attribute_1: str
"""
def __init__(self):
public_attribute_1 = ''
pass
class Child(Parent):
"""
=== Attributes ===
@type public_attribute_1: str
> Unresolved reference 'public_attribute_1'
@type public_attribute_2: str
"""
def __init__(self):
Parent.__init__(self)
public_attribute_2 = ''
pass
我理解public_attribute_1
不Child.__init__()
明确启动,但Child.__init__()
调用Parent.__init__(self)
从而启动public_attribute_1
。因此,所提出的错误涉及可读性和文档而不是功能。
我怎样才能使这样的代码更具可读性,而不插入冗余,从而击败整个继承点? 是否足以通过文档和注释进行彻底的文档化,并且忽略来自PyCharm的警告?或者是否有一种pythonic的方式呢?
什么是浮动'pass'es?你也应该使用'super().__ init __()'。 – jonrsharpe
我使用了'pass',因为这些类中的其他代码并不重要。我猜他们不是很有必要,但是你。 – Amaranth