Enums and Literals: false positive with @overload
/def method(self: Literal[SYMBOL], ...):
#15456
Labels
@overload
/def method(self: Literal[SYMBOL], ...):
#15456
Bug Report
This is probably the same underlying cause as issue #11759, but the proposed workaround there doesn't seem particularly appropriate for the case of
Enum
s andLiteral
s. I'd like to respectfully suggest that the issue be reconsidered in that light.I apologize if adding a comment to the closed issue was the right thing to do; I've filed a new issue out of concern that comments on a closed issue may not be noticed by folks' triage workflows.
As always: my thanks for this indispensable tool!
Hypothesis
The "erased type of self" (
[misc]
) check applies individually to each@overload
of a method, and not to the signature of the method as a whole. This results in undesirable errors when different@overload
s in combination handle the entire type ofself
(as withLiteral
s that add up to the entireEnum
or both values ofbool
), and even when one of the other@overload
s handles the erased self type in full (as with the third@overload
below).To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=52fd5335c1b73b28275aab67c2e01568
Expected Behavior
No errors are expected, since the overall signature of
is_letter()
accepts all possible values ofself
.Actual Behavior
Your Environment
mypy.ini
(and other config files): (none)The text was updated successfully, but these errors were encountered: