Skip to content

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

Merged
merged 4 commits into from
May 26, 2022
Merged

Conversation

JelleZijlstra
Copy link
Member

Part of #7928

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

AlexWaygood
AlexWaygood previously approved these changes May 25, 2022
Copy link
Member

@AlexWaygood AlexWaygood left a 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: ...

@AlexWaygood AlexWaygood dismissed their stale review May 25, 2022 14:13

Not sure we need so many overloads

@AlexWaygood
Copy link
Member

AlexWaygood commented May 25, 2022

It might also be good to rename the _T TypeVar to _NullTranslationsT now that it's bound to NullTranslations

@JelleZijlstra
Copy link
Member Author

Good point, you're right.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 84e2ea1 into python:master May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants