我正在尝试解决我在 pylint 中发现的大部分问题,但我在这个问题上遇到了麻烦:
C0103:变量名称“ELEMENT_CLASS”不符合 snake_case 命名风格(无效名称)
这是一段代码的例子:
def get_title(driver: Chrome) -> str:
"""
Extract title of the location section
"""
ELEMENT_CLASS = 'content-intro'
try:
element: WebElement = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable(
(
By.XPATH,
f'//div[contains(@class,"{ELEMENT_CLASS}")]')
)
)
except TimeoutException:
print(f'{ELEMENT_CLASS} could not be found')
raise
return element.text
我想表明我的类是硬编码的并且是常量。我虽然惯例是将它作为大写字母(例如在 vscode 中它以不同的颜色突出显示)。
我能做些什么来解决这个问题(正如 pylint 所希望的那样)?
注意:我不想在 pylintrc
或只是 type: ignore
中添加新规则。我想知道编写这种常量的“正确方法”或最常见的方法是什么。