Skip to content

Simpler/cleaner reveal_type()#20929

Open
ilevkivskyi wants to merge 8 commits intopython:masterfrom
ilevkivskyi:simple-reveal
Open

Simpler/cleaner reveal_type()#20929
ilevkivskyi wants to merge 8 commits intopython:masterfrom
ilevkivskyi:simple-reveal

Conversation

@ilevkivskyi
Copy link
Member

As discussed with @JukkaL, I only select most important things, but make the new behavior default. I will make the bulk of test output updates in a separate PR, here I only update tests where it is easier to update them, than to postpone.

Three main changes here:

  • Strip builtins. prefix everywhere.
  • Simpler type variables (no ids, no repeated defaults).
  • Cleaned-up, fixed, and unified handling on Unpack[...].

Few smaller notes:

  • In some cases we ignored options when formatting types (esp. in tests).
  • There is a bunch of code duplication, but it looks hard to fix, so I don't.
  • Single quotes for TypedDict names are redundant (just add to visual noise), so I remove them as well.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pytest-robotframework (https://github.com/detachhead/pytest-robotframework)
- pytest_robotframework/__init__.py:603: note:     def [P`-1] keyword(fn: Callable[P, Never]) -> Callable[P, Never]
+ pytest_robotframework/__init__.py:603: note:     def [P] keyword(fn: Callable[P, Never]) -> Callable[P, Never]
- pytest_robotframework/__init__.py:603: note:     def [P`-1, T] keyword(fn: Callable[P, AbstractContextManager[T, bool | None]]) -> Never
+ pytest_robotframework/__init__.py:603: note:     def [P, T] keyword(fn: Callable[P, AbstractContextManager[T, bool | None]]) -> Never
- pytest_robotframework/__init__.py:603: note:     def [P`-1, T] keyword(fn: Callable[P, T]) -> Callable[P, T]
+ pytest_robotframework/__init__.py:603: note:     def [P, T] keyword(fn: Callable[P, T]) -> Callable[P, T]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/tasks.py:1209: note:     def [P`-1, R] run_task(task: Task[P, R], task_run_id: UUID | None = ..., task_run: TaskRun | None = ..., parameters: dict[str, Any] | None = ..., wait_for: PrefectFuture[Any] | Any | Iterable[PrefectFuture[Any] | Any] | None = ..., return_type: Literal['state'] = ..., dependencies: dict[str, set[RunInput]] | None = ..., context: dict[str, Any] | None = ...) -> State[R]
+ src/prefect/tasks.py:1209: note:     def [P, R] run_task(task: Task[P, R], task_run_id: UUID | None = ..., task_run: TaskRun | None = ..., parameters: dict[str, Any] | None = ..., wait_for: PrefectFuture[Any] | Any | Iterable[PrefectFuture[Any] | Any] | None = ..., return_type: Literal['state'] = ..., dependencies: dict[str, set[RunInput]] | None = ..., context: dict[str, Any] | None = ...) -> State[R]
- src/prefect/tasks.py:1209: note:     def [P`-1, R] run_task(task: Task[P, R], task_run_id: UUID | None = ..., task_run: TaskRun | None = ..., parameters: dict[str, Any] | None = ..., wait_for: PrefectFuture[Any] | Any | Iterable[PrefectFuture[Any] | Any] | None = ..., return_type: Literal['result'] = ..., dependencies: dict[str, set[RunInput]] | None = ..., context: dict[str, Any] | None = ...) -> R
+ src/prefect/tasks.py:1209: note:     def [P, R] run_task(task: Task[P, R], task_run_id: UUID | None = ..., task_run: TaskRun | None = ..., parameters: dict[str, Any] | None = ..., wait_for: PrefectFuture[Any] | Any | Iterable[PrefectFuture[Any] | Any] | None = ..., return_type: Literal['result'] = ..., dependencies: dict[str, set[RunInput]] | None = ..., context: dict[str, Any] | None = ...) -> R

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/commands/menu.py:176: error: "_CallbackishT?[_MessageCallbackSigT`-1]" has no attribute "callback"  [attr-defined]
+ tanjun/commands/menu.py:176: error: "_CallbackishT?[_MessageCallbackSigT]" has no attribute "callback"  [attr-defined]
- tanjun/commands/menu.py:303: error: "_CallbackishT?[_UserCallbackSigT`-1]" has no attribute "callback"  [attr-defined]
+ tanjun/commands/menu.py:303: error: "_CallbackishT?[_UserCallbackSigT]" has no attribute "callback"  [attr-defined]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1155: note:     def [R, P`2223] builds(cls, type[BuildsWithSig[type[R], P]], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], 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[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]
- src/hydra_zen/structured_configs/_implementations.py:1155: note:     def [P`2225, R] builds(cls, Callable[P, R], /, *, zen_partial: Literal[False] | None = ..., populate_full_signature: Literal[True], 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[()] = ..., zen_dataclass: DataclassOptions | None = ..., frozen: bool = ..., zen_convert: ZenConvert | None = ...) -> type[BuildsWithSig[type[R], P]]
- src/hydra_zen/structured_configs/_implementations.py:1155: note:     def [P`2240, R, Importable: Callable[..., Any]] builds(cls, Callable[P, R] | type[Builds[Importable]] | Importable, /, *pos_args: T, zen_partial: bool | 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]] | type[ZenPartialBuilds[Importable]] | type[HydraPartialBuilds[Importable]] | type[BuildsWithSig[type[R], P]]

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.

1 participant