I have a class like this with field members consisting of different types, and inside my class I have __new__(cls, **kwargs)
and I would like to type hint **kwargs
.
from typing import Optional
@dataclass
class Foo
var1: int
var2: float
var3: bool
var4: str
var5: Optional[list[float]]
def __new__(cls, **kwargs) -> "Foo":
return super(Foo, cls).__new__(cls)
I ideally wanna be able to do something like
from typing import Optional
from typing_extensions import Unpack
@dataclass
class Foo
var1: int
var2: float
var3: bool
var4: str
var5: Optional[list[float]]
def __new__(cls, **kwargs: Unpack[Foo]) -> "Foo":
return super(Foo, cls).__new__(cls)
But referencing Foo
within __new__
isn’t possible.
New contributor
wordhydrogen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.