我不能在不添加# type:ignore || Used for pyright (Autocomplete)
的情况下分配变量,否则会出错。错误:[Pyright reportGeneralTypeIssues] [E] Argument of type "Column" cannot be assigned to parameter "id" of type "int" in function "__init__" "Column" is incompatible with "int"
(我使用SQLAlchemy btw)
我安装了有助于实现这一点的pip包sqlalchemy-stubs
。
https://github.com/dropbox/sqlalchemy-stubs
当您的扩展与程序中的某些变量类型不能正常工作时,您可以使用# type: ignore
。
它只在其范围内工作,所以…
# type: ignore
print(1 + 'x') # -> This won't throw errors
def foo():
return 2 + "!" # -> Neither this one will throw errors!
print(foo())
相反。。。
def foo():
# type: ignore
return 2 + "!" # -> This one won't throw errors
print(foo())
print(1 + 'x') # -> This one will throw an error!
# type: ignore
仅在其作用域内工作,如果放在全局作用域中程序的第一行,则会对整个脚本产生影响。