Closed smurfix closed 17 hours ago
The behavior you're suggesting here is not allowed by the Python typing spec currently. Mypy is correct to flag this as an error.
If you would like to propose an extension or amendment to the typing spec, you are welcome to follow the steps outlined here. There is already a draft PEP relating to sentinel values that is quite far along. It would cover your NotGiven
use case. It wouldn't cover Ellipsis
. However, the following is accepted by type checkers (requires Python 3.10 and newer):
from types import EllipsisType
def fn(x: int | None | EllipsisType = ...) -> None: ...
Ah. Thank you, I was not aware of these issues.
As the PEP seems to be reasonably far along, is there an effort to teach mypy about it?
There is no effort that I know of for supporting PEP 661 in mypy. It may be better to wait for a decision on the PEP.
Bug Report
Empty classes and similar types (e.g.
Ellipsis
) are often used as placeholders for an uber-None parameter, thus they should be allowed inLiteral[…]
. Currently they are not.To Reproduce
or
Expected Behavior
No error.
Actual Behavior
/tmp/tt.py:4: error: Parameter 1 of Literal[...] is invalid [valid-type]
Your Environment
mypy.ini
(and other config files): None