我收到來自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