python - PyCharm Asks "Is this intentional?" When Passing the Proper Arguments to Constructor of Generic Class
问题描述
In the following case, PyCharm 2020.2.3 (Professional Edition) Build #PY-202.7660.27 complains about me passing an int
to the constructor of the class (it underlines the 2
):
Passing int instead of [...].GenClass. Is this intentional?
from typing import Generic, TypeVar
A = TypeVar("A")
class GenClass(Generic[A]):
def __init__(self, p: int):
self.p = p
if __name__ == "__main__":
a = GenClass[str](2)
I'm using Python 3.9. The fact that it expects a GenClass
object seems to me like PyCharm wants the self
object from the constructor. That looks like an error but maybe I'm using generics the wrong way.
Could you please give me advice on whether the error is with me or with PyCharm? Thanks a lot!
解决方案
推荐阅读
- c# - 是否可以在 C# winforms 中一次将文本写入多个文本框?
- reactjs - 如何在 reactbootstrap 表搜索栏中添加 autocomplete=off 属性?
- javascript - 在单击 ReactJS 时添加输入
- javascript - 如何在 Javascript 的拼接数组中使用 .findIndex() 方法?
- javascript - 如何在 express 节点 js 中添加 sameSite=none 和安全
- postgresql - 如何在 Postgresql 中将 10.5 个月转换为 315 天?
- python - 在 sympy 中用隐函数求解 KKT 方程
- javascript - 基于 3 个多选选项隐藏表格行
- python - 如何使用 pandas 打开和修改 Excel 文件中的值
- linux-kernel - 有没有办法监控内核模块何时出现错误并相应地执行操作?