Clarification on typing.dataclass_transform() defaults
I cannot quite pinpoint the interaction of the defaults in typing.dataclass_transform() and __init_subclass__/__new__ parameters. PEP-681 does not seem to cover that at all, so perhaps I am missing something very obvious. Consider the following snippet
from typing import dataclass_transform
@dataclass_transform(order_default=True)
class Base:
def __init_subclass__(cls, *, order: bool = False): ...
class A(Base): ...
How should a type checker resolve the conflict between order_default= and order= in __init_subclass__? Is A ordered here? Is this a static error?
@superbobry, thanks for your question! Just wanted to respond to say that I saw this. Coincidentally, @erictraut and I, the authors of PEP 681, are both on vacation at the moment. One of us will reply when we're back.
@superbobry, sorry for the slow reply. As @debonte mentioned, we were both on vacation.
To answer your question above, it wouldn't make sense to default order to False in __init_subclass__ and then default it to True in the dataclass_transform. If you specify order_default=True in the dataclass_transform, then you are attesting to the fact that your implementation defaults to order=True (regardless of whether your implementation uses a custom metaclass or __init_subclass__.
Thanks for the clarification, Eric! Does that mean that the snippet in my original post should produce a static error?
No, static type checkers won't check for this error. If you assert that the order is True by default, then your implementation should honor that. This would be a really esoteric bug for static type checkers to explicitly check for.
Is there anything left to do here?
From my perspective, no there's nothing left to do here.