从dict继承时,mypy型统一
我希望以下代码可以打字,但事实并非如此。
from typing import Iterator, Type
class Parent(dict):
pass
class A(Parent):
pass
class B(Parent):
pass
x: Iterator[Type[Parent]] = (A, B).__iter__()
# error: Incompatible types in assignment (expression has type "Iterator[ABCMeta]", variable has type "Iterator[Type[Parent]]"
如果我将父班更改为,
class Parent():
pass
则可以正常工作。
有没有更好的方法让我让Mypy看到X
作为类型iterator [type [parent]]
时parent> parent> parent>从
dict
?
I would expect the following code to typecheck, but it does not.
from typing import Iterator, Type
class Parent(dict):
pass
class A(Parent):
pass
class B(Parent):
pass
x: Iterator[Type[Parent]] = (A, B).__iter__()
# error: Incompatible types in assignment (expression has type "Iterator[ABCMeta]", variable has type "Iterator[Type[Parent]]"
If I change the parent class to
class Parent():
pass
It works just fine.
Is there a better way for me to get mypy to see x
as a value of type Iterator[Type[Parent]]
when Parent
inherits from dict
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜在两行的工作中做这
件事有点过度捕食
doing it on two lines works
I guess mypy's a little overeager somewhere