Skip to content
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

Callable pretty #18245

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MechanicalConstruct
Copy link
Contributor

@hauntsaninja I started working on updating the argument printing to work as you specified. I was wondering if I should be updating format_callable_args as I have or whether this should be a more localized change particular to notes and leave everything else unchanged like error messages. This current change requires about 211 test cases to be changed which is why I think I'm going down the wrong path.

This comment has been minimized.

This comment has been minimized.

1 similar comment
Copy link
Contributor

github-actions bot commented Dec 7, 2024

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

operator (https://github.com/canonical/operator)
- ops/log.py:73: error: Incompatible types in assignment (expression has type "Callable[[type[BaseException], BaseException, TracebackType], Any]", variable has type "Callable[[type[BaseException], BaseException, TracebackType | None], Any]")  [assignment]
+ ops/log.py:73: error: Incompatible types in assignment (expression has type "(type[BaseException], BaseException, TracebackType) -> Any", variable has type "(type[BaseException], BaseException, TracebackType | None) -> Any")  [assignment]
- ops/framework.py:601: error: Incompatible redefinition (redefinition with type "Callable[[Framework], FrameworkEvents]", original type "FrameworkEvents")  [misc]
+ ops/framework.py:601: error: Incompatible redefinition (redefinition with type "(Framework) -> FrameworkEvents", original type "FrameworkEvents")  [misc]
- ops/framework.py:1096: error: Invalid signature "Callable[[BoundStoredState, Literal['on']], ObjectEvents]" for "__getattr__"  [misc]
+ ops/framework.py:1096: error: Invalid signature "(BoundStoredState, Literal['on']) -> ObjectEvents" for "__getattr__"  [misc]
- ops/charm.py:1331: error: Incompatible redefinition (redefinition with type "Callable[[CharmBase], CharmEvents]", original type "CharmEvents")  [misc]
+ ops/charm.py:1331: error: Incompatible redefinition (redefinition with type "(CharmBase) -> CharmEvents", original type "CharmEvents")  [misc]

pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/dataclasses.py:214: note:     def dataclass(None, /) -> Callable[[type[_T]], type[_T]]
+ pydantic/v1/dataclasses.py:214: note:     def dataclass(None, /) -> (type[_T]) -> type[_T]
- pydantic/v1/dataclasses.py:214: note:     def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., match_args: bool = ..., kw_only: bool = ..., slots: bool = ..., weakref_slot: bool = ...) -> Callable[[type[_T]], type[_T]]
+ pydantic/v1/dataclasses.py:214: note:     def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., match_args: bool = ..., kw_only: bool = ..., slots: bool = ..., weakref_slot: bool = ...) -> (type[_T]) -> type[_T]
- pydantic/_internal/_decorators.py:197: error: Incompatible return value type (got "Callable[[VarArg(Any), KwArg(Any)], ReturnType] | Any", expected "PydanticDescriptorProxy[ReturnType]")  [return-value]
+ pydantic/_internal/_decorators.py:197: error: Incompatible return value type (got "(Any, Any) -> ReturnType | Any", expected "PydanticDescriptorProxy[ReturnType]")  [return-value]
- pydantic/_internal/_generate_schema.py:416: error: "Callable[[object], Any]" has no attribute "__func__"  [attr-defined]
+ pydantic/_internal/_generate_schema.py:416: error: "(object) -> Any" has no attribute "__func__"  [attr-defined]
- pydantic/_internal/_generate_schema.py:2287: error: Invalid index type "tuple[Literal['before', 'after', 'wrap', 'plain'], str]" for "Mapping[tuple[Literal['before', 'after', 'wrap', 'plain'], Literal['no-info', 'with-info']], Callable[[Callable[..., Any], Any, str | None], Any]]"; expected type "tuple[Literal['before', 'after', 'wrap', 'plain'], Literal['no-info', 'with-info']]"  [index]
+ pydantic/_internal/_generate_schema.py:2287: error: Invalid index type "tuple[Literal['before', 'after', 'wrap', 'plain'], str]" for "Mapping[tuple[Literal['before', 'after', 'wrap', 'plain'], Literal['no-info', 'with-info']], ((..., Any), Any, str | None) -> Any]"; expected type "tuple[Literal['before', 'after', 'wrap', 'plain'], Literal['no-info', 'with-info']]"  [index]
- pydantic/fields.py:517: note:     def Field(default, default: EllipsisType, *, alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: Callable[[str, FieldInfo], str] | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> Any
+ pydantic/fields.py:517: note:     def Field(default, default: EllipsisType, *, alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: (str, FieldInfo) -> str | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | (JsonDict) -> None | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> Any
- pydantic/fields.py:517: note:     def [_T] Field(default, default: _T, *, alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: Callable[[str, FieldInfo], str] | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> _T
+ pydantic/fields.py:517: note:     def [_T] Field(default, default: _T, *, alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: (str, FieldInfo) -> str | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | (JsonDict) -> None | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> _T
- pydantic/fields.py:517: note:     def [_T] Field(default_factory, *, default_factory: Callable[[], _T] | Callable[[dict[str, Any]], _T], alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: Callable[[str, FieldInfo], str] | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> _T
+ pydantic/fields.py:517: note:     def [_T] Field(default_factory, *, default_factory: () -> _T | (dict[str, Any]) -> _T, alias: str | None = ..., alias_priority: int | None = ..., validation_alias: str | AliasPath | AliasChoices | None = ..., serialization_alias: str | None = ..., title: str | None = ..., field_title_generator: (str, FieldInfo) -> str | None = ..., description: str | None = ..., examples: list[Any] | None = ..., exclude: bool | None = ..., discriminator: str | Discriminator | None = ..., deprecated: deprecated | str | bool | None = ..., json_schema_extra: JsonDict | (JsonDict) -> None | None = ..., frozen: bool | None = ..., validate_default: bool | None = ..., repr: bool = ..., init: bool | None = ..., init_var: bool | None = ..., kw_only: bool | None = ..., pattern: str | Pattern[str] | None = ..., strict: bool | None = ..., coerce_numbers_to_str: bool | None = ..., gt: Any | None = ..., ge: Any | None = ..., lt: Any | None = ..., le: Any | None = ..., multiple_of: float | None = ..., allow_inf_nan: bool | None = ..., max_digits: int | None = ..., decimal_places: int | None = ..., min_length: int | None = ..., max_length: int | None = ..., union_mode: Literal['smart', 'left_to_right'] = ..., fail_fast: bool | None = ...) -> _T

... (truncated 26 lines) ...

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/dependencies/data.py:220: error: Argument "callback" to "inject" has incompatible type "Callable[..., Coroutine[Any, Any, _T]]"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/dependencies/data.py:220: error: Argument "callback" to "inject" has incompatible type "(..., Coroutine[Any, Any, _T])"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/dependencies/data.py:347: error: Argument "callback" to "inject" has incompatible type "Callable[..., Coroutine[Any, Any, _T]]"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/dependencies/data.py:347: error: Argument "callback" to "inject" has incompatible type "(..., Coroutine[Any, Any, _T])"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/schedules.py:347: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "_CallbackSigT"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/schedules.py:347: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "_CallbackSigT"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/schedules.py:373: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "Callable[..., Coroutine[Any, Any, None]]"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
- tanjun/schedules.py:396: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "Callable[..., Coroutine[Any, Any, None]]"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/schedules.py:373: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "(..., Coroutine[Any, Any, None])"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
+ tanjun/schedules.py:396: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "(..., Coroutine[Any, Any, None])"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/schedules.py:1067: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "_CallbackSigT"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/schedules.py:1067: error: Argument 1 to "call_with_async_di" of "Client" has incompatible type "_CallbackSigT"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/commands/slash.py:268: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:268: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:268: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:268: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "(MessageContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:377: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:377: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:377: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:377: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "(MessageContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1277: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1277: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1277: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1277: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "(MessageContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1331: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1331: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1331: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1331: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "(MessageContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1525: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1525: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:1525: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/slash.py:1525: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "(MessageContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/slash.py:3191: error: Argument 1 to "call_with_async_di" of "Context" has incompatible type "_SlashCallbackSigT"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/commands/slash.py:3191: error: Argument 1 to "call_with_async_di" of "Context" has incompatible type "_SlashCallbackSigT"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/commands/slash.py:3222: error: Incompatible types in assignment (expression has type "Callable[[AutocompleteContext, float, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None", variable has type "Callable[[AutocompleteContext, str, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None")  [assignment]
- tanjun/commands/slash.py:3225: error: Incompatible types in assignment (expression has type "Callable[[AutocompleteContext, int, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None", variable has type "Callable[[AutocompleteContext, str, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None")  [assignment]
- tanjun/commands/slash.py:3235: error: Argument 1 to "call_with_async_di" of "Context" has incompatible type "Callable[[AutocompleteContext, str, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"; expected "Callable[..., Coroutine[Any, Any, Never] | Never]"  [arg-type]
+ tanjun/commands/slash.py:3222: error: Incompatible types in assignment (expression has type "(AutocompleteContext, float, Any, Any) -> Coroutine[Any, Any, None] | None", variable has type "(AutocompleteContext, str, Any, Any) -> Coroutine[Any, Any, None] | None")  [assignment]
+ tanjun/commands/slash.py:3225: error: Incompatible types in assignment (expression has type "(AutocompleteContext, int, Any, Any) -> Coroutine[Any, Any, None] | None", variable has type "(AutocompleteContext, str, Any, Any) -> Coroutine[Any, Any, None] | None")  [assignment]
+ tanjun/commands/slash.py:3235: error: Argument 1 to "call_with_async_di" of "Context" has incompatible type "(AutocompleteContext, str, Any, Any) -> Coroutine[Any, Any, None]"; expected "(..., Coroutine[Any, Any, Never] | Never)"  [arg-type]
- tanjun/commands/message.py:78: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/message.py:78: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/message.py:78: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/message.py:78: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "(SlashContext, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/message.py:105: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]
+ tanjun/commands/message.py:105: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "(MenuContext, Any, Any, Any) -> Coroutine[Any, Any, None]"  [type-var]
- tanjun/commands/message.py:105: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]"  [type-var]

... (truncated 51 lines) ...

manticore (https://github.com/trailofbits/manticore)
- manticore/native/manticore.py:296: error: Incompatible types in assignment (expression has type "Callable[[Any, Any], Any]", variable has type "Callable[[Any, Any, Any], Any] | Callable[[Any, Any, Any, Any], Any]")  [assignment]
+ manticore/native/manticore.py:296: error: Incompatible types in assignment (expression has type "(Any, Any) -> Any", variable has type "(Any, Any, Any) -> Any | (Any, Any, Any, Any) -> Any")  [assignment]

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/dispatch.py:41: error: Argument 1 to "filter" has incompatible type "Callable[[Any], bool]"; expected "Callable[[dict[str, type[Any]] | None], TypeGuard[dict[str, T] | None]]"  [arg-type]
+ src/prefect/utilities/dispatch.py:41: error: Argument 1 to "filter" has incompatible type "(Any) -> bool"; expected "(dict[str, type[Any]] | None) -> TypeGuard[dict[str, T] | None]"  [arg-type]
- src/prefect/utilities/dispatch.py:126: error: Incompatible types in assignment (expression has type "Callable[[Any, KwArg(Any)], Any]", variable has type "Callable[[], None]")  [assignment]
+ src/prefect/utilities/dispatch.py:126: error: Incompatible types in assignment (expression has type "(Any, Any) -> Any", variable has type "() -> None")  [assignment]
- src/prefect/utilities/pydantic.py:87: error: Incompatible types in assignment (expression has type "Callable[[Any], Any]", variable has type "Callable[[], str | tuple[Any, ...]]")  [assignment]
+ src/prefect/utilities/pydantic.py:87: error: Incompatible types in assignment (expression has type "(Any) -> Any", variable has type "() -> str | tuple[Any, ...]")  [assignment]
- src/prefect/utilities/pydantic.py:194: error: Incompatible types in assignment (expression has type "Callable[[type[M], KwArg(Any)], M]", variable has type overloaded function)  [assignment]
+ src/prefect/utilities/pydantic.py:194: error: Incompatible types in assignment (expression has type "(type[M], Any) -> M", variable has type overloaded function)  [assignment]
- src/prefect/utilities/pydantic.py:298: error: Value of type "dict[Any, Callable[[type[Any]], Any]] | None" is not indexable  [index]
+ src/prefect/utilities/pydantic.py:298: error: Value of type "dict[Any, (type[Any]) -> Any] | None" is not indexable  [index]
- src/prefect/utilities/callables.py:406: error: Incompatible types in assignment (expression has type "Callable[[str, Any, KwArg(Any)], Any]", variable has type "Callable[[str, Any | None, type[Any] | None, KwArg(Any)], Any]")  [assignment]
+ src/prefect/utilities/callables.py:406: error: Incompatible types in assignment (expression has type "(str, Any, Any) -> Any", variable has type "(str, Any | None, type[Any] | None, Any) -> Any")  [assignment]
- src/prefect/_internal/concurrency/threads.py:31: error: Attribute function "_counter" with type "Callable[[], int]" does not accept self argument  [misc]
+ src/prefect/_internal/concurrency/threads.py:31: error: Attribute function "_counter" with type "() -> int" does not accept self argument  [misc]
- src/prefect/_internal/concurrency/api.py:133: note:          abstractstaticmethod[[Callable[[], _R_co] | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
+ src/prefect/_internal/concurrency/api.py:133: note:          abstractstaticmethod[[() -> _R_co | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
- src/prefect/_internal/concurrency/api.py:133: note:          def [T] wait_for_call_in_loop_thread(Callable[[], Awaitable[T]] | Call[Awaitable[T]], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ..., contexts: Iterable[ContextManager[Any]] | None = ...) -> Coroutine[Any, Any, Awaitable[T]]
+ src/prefect/_internal/concurrency/api.py:133: note:          def [T] wait_for_call_in_loop_thread(() -> Awaitable[T] | Call[Awaitable[T]], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ..., contexts: Iterable[ContextManager[Any]] | None = ...) -> Coroutine[Any, Any, Awaitable[T]]
- src/prefect/_internal/concurrency/api.py:151: note:          abstractstaticmethod[[Callable[[], _R_co] | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
+ src/prefect/_internal/concurrency/api.py:151: note:          abstractstaticmethod[[() -> _R_co | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
- src/prefect/_internal/concurrency/api.py:151: note:          def [T] wait_for_call_in_new_thread(Callable[[], T] | Call[T], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ...) -> Coroutine[Any, Any, T]
+ src/prefect/_internal/concurrency/api.py:151: note:          def [T] wait_for_call_in_new_thread(() -> T | Call[T], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ...) -> Coroutine[Any, Any, T]
- src/prefect/_internal/concurrency/api.py:182: note:          abstractstaticmethod[[Callable[[], _R_co] | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
+ src/prefect/_internal/concurrency/api.py:182: note:          abstractstaticmethod[[() -> _R_co | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
- src/prefect/_internal/concurrency/api.py:182: note:          def [T] wait_for_call_in_loop_thread(Callable[[], Awaitable[T]] | Callable[[], Awaitable[T]] | Call[Awaitable[T]], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ..., contexts: Iterable[ContextManager[Any]] | None = ...) -> Awaitable[T]
+ src/prefect/_internal/concurrency/api.py:182: note:          def [T] wait_for_call_in_loop_thread(() -> Awaitable[T] | () -> Awaitable[T] | Call[Awaitable[T]], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ..., contexts: Iterable[ContextManager[Any]] | None = ...) -> Awaitable[T]
- src/prefect/_internal/concurrency/api.py:203: note:          abstractstaticmethod[[Callable[[], _R_co] | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
+ src/prefect/_internal/concurrency/api.py:203: note:          abstractstaticmethod[[() -> _R_co | Call[_R_co], float | None, Iterable[Call[Any]] | None], _R_co]
- src/prefect/_internal/concurrency/api.py:203: note:          def [T] wait_for_call_in_new_thread(Callable[[], T] | Call[T], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ...) -> Call[T]
+ src/prefect/_internal/concurrency/api.py:203: note:          def [T] wait_for_call_in_new_thread(() -> T | Call[T], /, timeout: float | None = ..., done_callbacks: Iterable[Call[Any]] | None = ...) -> Call[T]
- src/prefect/_internal/concurrency/api.py:234: error: Argument 1 to "call_soon_in_loop_thread" of "_base" has incompatible type "Callable[[], Awaitable[T]] | Call[Awaitable[T]]"; expected "Callable[[], Awaitable[Awaitable[T]]] | Call[Awaitable[Awaitable[T]]]"  [arg-type]
+ src/prefect/_internal/concurrency/api.py:234: error: Argument 1 to "call_soon_in_loop_thread" of "_base" has incompatible type "() -> Awaitable[T] | Call[Awaitable[T]]"; expected "() -> Awaitable[Awaitable[T]] | Call[Awaitable[Awaitable[T]]]"  [arg-type]
- src/prefect/utilities/asyncutils.py:402: error: Argument 1 to "is_async_fn" has incompatible type "Callable[..., Coroutine[Any, Any, R]]"; expected "Callable[[VarArg(Never), KwArg(Never)], Never] | Callable[[VarArg(Never), KwArg(Never)], Awaitable[Never]]"  [arg-type]
+ src/prefect/utilities/asyncutils.py:402: error: Argument 1 to "is_async_fn" has incompatible type "(..., Coroutine[Any, Any, R])"; expected "(Never, Never) -> Never | (Never, Never) -> Awaitable[Never]"  [arg-type]
- src/prefect/events/related.py:97: error: Argument "client_method" to "_get_and_cache_related_object" has incompatible type "Callable[[UUID], Coroutine[Any, Any, FlowRun]]"; expected "Callable[[UUID | str], Awaitable[ObjectBaseModel | None]]"  [arg-type]
+ src/prefect/events/related.py:97: error: Argument "client_method" to "_get_and_cache_related_object" has incompatible type "(UUID) -> Coroutine[Any, Any, FlowRun]"; expected "(UUID | str) -> Awaitable[ObjectBaseModel | None]"  [arg-type]
- src/prefect/events/related.py:120: error: Argument "client_method" to "_get_and_cache_related_object" has incompatible type "Callable[[UUID], Coroutine[Any, Any, Flow]]"; expected "Callable[[UUID | str], Awaitable[ObjectBaseModel | None]]"  [arg-type]
+ src/prefect/events/related.py:120: error: Argument "client_method" to "_get_and_cache_related_object" has incompatible type "(UUID) -> Coroutine[Any, Any, Flow]"; expected "(UUID | str) -> Awaitable[ObjectBaseModel | None]"  [arg-type]
- src/prefect/events/related.py:128: error: Argument "client_method" to "_get_and_cache_related_object" has incompatible type "Callable[[UUID], Coroutine[Any, Any, DeploymentResponse]]"; expected "Callable[[UUID | str], Awaitable[ObjectBaseModel | None]]"  [arg-type]

... (truncated 509 lines) ...```

@MechanicalConstruct MechanicalConstruct marked this pull request as ready for review December 7, 2024 02:03
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I wonder if we should still use the the Callable[...] syntax for simple function signatures, where all arguments are positional-only without defaults (and no *args). This way the reported types match the types the user would use in an annotation. However, then different callable types would be reported differently, which wouldn't be ideal either.

We currently use the syntax def (<args>) -> ret for callable types in reveal_type output. For consistency, I think it would be good to include the def prefix here as well. Example:

def f(x: int) -> str: return ""

reveal_type(f)  # Revealed type is "def (x: builtins.int) -> builtins.str"

(But we don't want the builtins. prefix and other things that reveal_type uses that are different from normal error messages and would be too verbose.)

@@ -2039,6 +2025,7 @@ def report_non_method_protocol(
def note_call(
self, subtype: Type, call: Type, context: Context, *, code: ErrorCode | None
) -> None:
# breakpoint()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers from debugging?

@hamdanal
Copy link
Collaborator

- tanjun/commands/slash.py:3222: error: Incompatible types in assignment (expression has type "Callable[[AutocompleteContext, float, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None", variable has type "Callable[[AutocompleteContext, str, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]] | None")  [assignment]
+ tanjun/commands/slash.py:3222: error: Incompatible types in assignment (expression has type "(AutocompleteContext, float, Any, Any) -> Coroutine[Any, Any, None] | None", variable has type "(AutocompleteContext, str, Any, Any) -> Coroutine[Any, Any, None] | None")  [assignment]

I think the whole (arg1: Type1, arg2: Type2) -> Return syntax should be parenthesized to avoid confusion otherwise both Callable[[int], str] | None and Callable[[int], str | None] would render as (int) -> str | None.

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.

3 participants