我有两个使用attrs 包的装饰类,如下所示:
@attr.s(kw_only=True)
class Entity:
"""
base class of all entities
"""
entity_id = attr.ib(type=str)
# ...
@attr.s(kw_only=True)
class Customer(Entity):
customer_name = attr.ib(type=Name)
# ...
我得到Unexpected keyword argument "entity_id" for "Customer"
这样的代码:
def register_customer(customer_name: str):
return Customer(
entity_id=unique_id_generator(),
customer_name=Name(full_name=customer_name),
)
那么如何让Mypy知道__init__
我的父类的方法。我应该提到代码运行良好,并且(至少看起来)没有运行时错误。