That’s an interesting idea, but no we do not consider the return type of decorators when looking for fields.
-Erik
From: Patrick Arminio <patrick.arminio@gmail.com>
Sent: Sunday, March 6, 2022 5:23 PM
To: David Foster <davidfstr@gmail.com>
Cc: Erik De Bonte <Erik.DeBonte@microsoft.com>; typing-sig@python.org
Subject: Re: [Typing-sig] Re: Dataclass Transform draft PEP
Does the PEP/implementation take into account the return type specified in the functions signature?
For example, assuming we had Intersection as a type, would this work?
class HasSomeAttr(typing.Protocol):
attr: str
@typing.dataclass_transform(
kw_only_default=True,
field_descriptors=(model_field, ))
def create_model(
*,
init: bool = True,
) -> Callable[[Type[_T]], typing.Intersection[Type[_T], HasSomeAttr]]: ...
--
Patrick Arminio