Open Daverball opened 7 months ago
This relates to a part of the typing spec that is currently unspecified but that I hope to clarify soon. The question is whether self
and cls
parameters should be considered position-only. When discussing this in the typing forum, the community consensus (including input from Guido) seems to be that self
and cls
should always be considered position-only even if they're not explicitly marked as such, and it should be considered an error to use a keyword argument to target these parameters. The next step is to formalize this decision and propose an update to the typing spec with wording that codifies this behavior.
Bug Report
This is admittedly a fairly niche use-case, but this came up when adding more precise type hints to
itsdangerous
and trying to write aProtocol
that accepts any object that has aloads
anddumps
method wheredumps
can take arbitrary extra keyword arguments.The docs for
--extra-checks
state that uses ofConcatenate
will force positional-only for equality, but this seems incorrect to me in the specific case of a property on aProtocol
, since we're performing a structural match against methods there.*args: Any, **kwargs: Any
doesn't really work, because it will only be recognized as a gradual extension of the method by some type checkers and not consistently, it's also not part of the typing spec, unless I'm mistaken. SoConcatenate
with...
is the only way to spell this.To Reproduce mypy Playground
Expected Behavior
I would expect
MySerializer
to match theProtocol
in my example. As soon as I change thepayload
argument to positional-only it does. It also does if I disable--extra-checks
.Actual Behavior
It is rejected based on the first argument not being positional-only.
Your Environment
mypy.ini
(and other config files):