Open
Description
Currently, we use an extra str
overload when using literals. For example:
@overload
def open(mode: Literal["r"] = ...) -> int: ...
@overload
def open(mode: Literal["w"]) -> str: ...
@overload
def open(mode: str) -> str | int: ...
What's the use case for this? The only thing I can think of is something like this:
mode: str = ...
open(mode)
But this actually looks like a typing error to me where mode
should have been annotated with Literal["r", "w"]
anyway. I would suggest starting to remove these defaults, possibly after the next mypy version is released. primer should warn us if this causes lots of new errors (as I would expect for e.g builtins.open()
) and we can then decide on a case-by-case basis to leave the default in for now.
Side note: We can't do this for bool
yet due to python/mypy#6113.