我尝试导入的模块是pyinputplus。如果程序导入模块并正常使用其所有功能,我不知道为什么它会显示错误。
以下是错误消息:
Cannot import 'pyinputplus' due to syntax error 'invalid syntax (<unknown>, line 268)'pylint(syntax-error)我可以使用它,因为它不会损害功能,但当我在IDE中工作时,它确实让我恼火并分散了我的注意力。此外,这可能是某些设置不正确的迹象。
发布于 2020-09-14 19:31:45
问题在于文件中各行的顺序。
函数inputStr()的类型被正确识别
.....表示线条的截断
def inputStr(
prompt="",
.....):
# type: (str, .....) -> Any
"""Prompts the user to enter .....
"""对于inputCustom(),类型识别不正确,因为类型行不正确
def inputCustom(
# type: (Callable, str, .....) -> Any
customValidationFunc,
prompt="",
.....):
"""Prompts the user to enter input. ....."""它应该在参数列表之后。
def inputCustom(
customValidationFunc, prompt="", .....):
# type: (Callable, str, .....) -> Any
"""Prompts the user to enter input. ....."""对函数inputNum()执行相同的操作
可以编辑__init__.py文件并将两个注释行移动到正确的位置。
然后,VSC将在工具提示中显示该类型。
我已经为它创建了一个Issue at pyinputplus。
编辑:
我已经研究了为什么pylint会显示这个隐秘的错误,问题是当您使用type_comments=True编译时,Python3.8编译器会将其报告为语法错误。Pylint首先尝试使用type_comments=True进行编译,但没有正确测试Python3.8异常。
我已经写了一个replacement for astroid/builder.py::_parse_string()。该行不再报告为错误。也许当他们使用重写时,他们会为错误的类型注解添加一个错误。
发布于 2020-09-24 15:09:27
我是PyInputPlus的创建者。谢谢你指出这一点。我已经更正了PyInputPlus 0.2.11中的类型提示拼写错误。解决方案是通过运行pip install -U pyinputplus进行升级。
https://stackoverflow.com/questions/63877895
复制相似问题