-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
gettext: fix unconstrained TypeVar #7935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the 3.11 branch: which calls will be incorrectly inferred (or incorrectly disallowed) if we omit overloads 2-4 here? Could we not just do the following, using only 4 overloads instead of 7?
Overloads 2 and 3
These are the Literal[True]
overloads, but they're covered by the final bool
fallback overload, since the return type is the same.
Overload 4
This can be combined with the final fallback overload, since the return type is the same. For the final overload, we can just have the class_
parameter as Callable[[io.BufferedReader], _T] | None
instead of Callable[[io.BufferedReader], _T]
.
@overload
def translation(
domain: str,
localedir: StrPath | None = ...,
languages: Iterable[str] | None = ...,
class_: None = ...,
fallback: Literal[False] = ...,
) -> GNUTranslations: ...
@overload
def translation(
domain: str,
localedir: StrPath | None = ...,
languages: Iterable[str] | None = ...,
*,
class_: Callable[[io.BufferedReader], _T],
fallback: Literal[False] = ...,
) -> _T: ...
@overload
def translation(
domain: str,
localedir: StrPath | None,
languages: Iterable[str] | None,
class_: Callable[[io.BufferedReader], _T],
fallback: Literal[False] = ...,
) -> _T: ...
@overload
def translation(
domain: str,
localedir: StrPath | None = ...,
languages: Iterable[str] | None = ...,
class_: Callable[[io.BufferedReader], NullTranslations] | None = ...,
fallback: bool = ...,
) -> NullTranslations: ...
It might also be good to rename the |
Good point, you're right. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Part of #7928