请检查以下简单代码。
@dataclass
class FooData:
bar: int
baz: str
FooData(1, 's') # works fine
def through() -> Type[FooData]:
return FooData
DataClass = through()
DataClass(1, 's') # warning, unexpected arguments输入带有返回TypeDataclass的函数或方法的提示不起作用。
是PyCharm错误还是我做错了什么?
Pycharm版本: PyCharm 2021.3.3 (专业版)
发布于 2022-08-18 07:12:43
PyCharm处理装饰师的方式似乎是个问题。我也有同样的问题。做同样的事情,但也指定相应的__init__方法,使它的行为与预期的一样。
我建议改用皮丹模型。它们做同样的事情,正确地处理,并提供了一堆很好的附加特性,包括但不限于自动验证。唯一的区别是,它们要求您使用关键字-参数进行初始化。
下面是一个例子。
from pydantic import BaseModel
from typing import Type
class FooData(BaseModel):
bar: int
baz: str
FooData(bar=1, baz='s') # works fine
def through() -> Type[FooData]:
return FooData
Model = through()
Model(bar=1, baz='s') # also works fine除此之外,这还需要在“JetBrains问题跟踪器”上开一张票。
https://stackoverflow.com/questions/73398567
复制相似问题