-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix TypeVar upper bounds sometimes not being displayed in pretty callables #17802
Merged
JelleZijlstra
merged 1 commit into
python:master
from
brianschubert:gh-17792-typevar-upper-bound
Sep 21, 2024
Merged
Fix TypeVar upper bounds sometimes not being displayed in pretty callables #17802
JelleZijlstra
merged 1 commit into
python:master
from
brianschubert:gh-17792-typevar-upper-bound
Sep 21, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diff from mypy_primer, showing the effect of this PR on open source code: hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1137: note: def [Importable] builds(cls, type[Builds[Importable]] | type[BuildsWithSig[Importable, Any]], /, *pos_args: T, zen_partial: Literal[False] | None = ..., populate_full_signature: bool = ..., zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[type[DataClass_], ...] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ..., **kwargs_for_target: T) -> type[Builds[Importable]]
+ src/hydra_zen/structured_configs/_implementations.py:1137: note: def [Importable: Callable[..., Any]] builds(cls, type[Builds[Importable]] | type[BuildsWithSig[Importable, Any]], /, *pos_args: T, zen_partial: Literal[False] | None = ..., populate_full_signature: bool = ..., zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[type[DataClass_], ...] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ..., **kwargs_for_target: T) -> type[Builds[Importable]]
- src/hydra_zen/structured_configs/_implementations.py:1137: note: def [Importable] builds(cls, Importable, /, *pos_args: T, zen_partial: Literal[False] | None = ..., populate_full_signature: bool = ..., zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[type[DataClass_], ...] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ..., **kwargs_for_target: T) -> type[Builds[Importable]]
+ src/hydra_zen/structured_configs/_implementations.py:1137: note: def [Importable: Callable[..., Any]] builds(cls, Importable, /, *pos_args: T, zen_partial: Literal[False] | None = ..., populate_full_signature: bool = ..., zen_wrappers: Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None | Sequence[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]] | ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]] | Just[Callable[[Callable[..., Any]], Callable[..., Any]]] | type[Builds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[ZenPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[HydraPartialBuilds[Callable[[Callable[..., Any]], Callable[..., Any]]]] | type[Just[Callable[[Callable[..., Any]], Callable[..., Any]]]] | Callable[[Callable[..., Any]], Callable[..., Any]] | str | None] = ..., zen_meta: Mapping[str, SupportedPrimitive] | None = ..., hydra_recursive: bool | None = ..., hydra_convert: Literal['none', 'partial', 'all', 'object'] | None = ..., hydra_defaults: list[str | DataClass_ | type[DataClass_] | Mapping[str, str | Sequence[str] | None]] | None = ..., dataclass_name: str | None = ..., builds_bases: tuple[type[DataClass_], ...] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ..., **kwargs_for_target: T) -> type[Builds[Importable]]
... (truncated 12 lines) ...
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/help.py:1237: note: def [BotT] prepare_help_command(self, Context[BotT], str | None = ..., /) -> Coroutine[Any, Any, None]
+ discord/ext/commands/help.py:1237: note: def [BotT: Bot | AutoShardedBot] prepare_help_command(self, Context[BotT], str | None = ..., /) -> Coroutine[Any, Any, None]
- discord/ext/commands/help.py:1237: note: def [BotT] prepare_help_command(self, Context[BotT], str | None, /) -> Coroutine[Any, Any, None]
+ discord/ext/commands/help.py:1237: note: def [BotT: Bot | AutoShardedBot] prepare_help_command(self, Context[BotT], str | None, /) -> Coroutine[Any, Any, None]
- discord/ext/commands/help.py:1500: note: def [BotT] prepare_help_command(self, Context[BotT], str | None = ..., /) -> Coroutine[Any, Any, None]
+ discord/ext/commands/help.py:1500: note: def [BotT: Bot | AutoShardedBot] prepare_help_command(self, Context[BotT], str | None = ..., /) -> Coroutine[Any, Any, None]
- discord/ext/commands/help.py:1500: note: def [BotT] prepare_help_command(self, Context[BotT], str | None, /) -> Coroutine[Any, Any, None]
+ discord/ext/commands/help.py:1500: note: def [BotT: Bot | AutoShardedBot] prepare_help_command(self, Context[BotT], str | None, /) -> Coroutine[Any, Any, None]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/gateway.py:825: note: def [ProtoMsgsT] wait_for(self, *, emsg: EMsg | None, check: Callable[[ProtoMsgsT], bool] = ...) -> Future[ProtoMsgsT]
+ steam/gateway.py:825: note: def [ProtoMsgsT: ProtobufMessage | Message] wait_for(self, *, emsg: EMsg | None, check: Callable[[ProtoMsgsT], bool] = ...) -> Future[ProtoMsgsT]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/elements/layouts_test.py:581:14: note: def [F] dialog_decorator(title: F, *, width: Literal['small', 'large'] = ...) -> F
+ lib/tests/streamlit/elements/layouts_test.py:581:14: note: def [F: Callable[..., None]] dialog_decorator(title: F, *, width: Literal['small', 'large'] = ...) -> F
- lib/tests/streamlit/elements/layouts_test.py:595:14: note: def [F] dialog_decorator(title: F, *, width: Literal['small', 'large'] = ...) -> F
+ lib/tests/streamlit/elements/layouts_test.py:595:14: note: def [F: Callable[..., None]] dialog_decorator(title: F, *, width: Literal['small', 'large'] = ...) -> F
- lib/tests/streamlit/runtime/caching/cache_data_api_test.py:356:14: note: def [F] __call__(self, func: F) -> F
+ lib/tests/streamlit/runtime/caching/cache_data_api_test.py:356:14: note: def [F: Callable[..., Any]] __call__(self, func: F) -> F
|
JelleZijlstra
approved these changes
Sep 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #17792. Related to #17791.
Currently,
pretty_callable
only rendersTypeVar
upper bounds if they are of typeInstance
:mypy/mypy/messages.py
Lines 2943 to 2949 in 5dfc7d9
However, there are some types that can appear as
TypeVar
upper bounds which are not represented byInstance
, such asUnionType
andCallableType
.This PR allows such non-
Instance
upper bounds to be rendered as well.Effect
Consider the below code.
Playground link: https://mypy-play.net/?mypy=1.11.2&python=3.12&enable-incomplete-feature=NewGenericSyntax&gist=ba30c820cc3668e0919dadf2f391ff4b
Before
def [T] f1(x: T) -> T
(upper bound missing). Duplicate entries are suppressed.def [T] f2(x: T) -> T
(upper bound missing), and is removed as an apparent duplicate of the first.After