Skip to content

Handle more ParamSpec literal form special cases - #15256

Open
A5rocks wants to merge 1 commit into
python:masterfrom
A5rocks:fix-ps-literal-special-case
Open

A5rocks wants to merge 1 commit into
python:masterfrom
A5rocks:fix-ps-literal-special-case

Conversation

@A5rocks

@A5rocks A5rocks commented May 16, 2023 •

Copy link
Copy Markdown
Collaborator

This is more:tm: correct as shown by changes in test cases. I can't find any issues that are closed by this though. From what I remember, this was a followup fix for #14903 in order to fix some incorrect mypy-primer output.

This just removes a previous too-broad special case for Z[Any] where Z has a single paramspec parameter. Previously, this would be equivalent to Z[...]. Now, it is equivalent to Z[[Any]], unless the Any is from an error (invalid paramspec expressions will return an Any with TypeOfAny.from_error).

EDIT: Oh yeah, this also addresses one case where this "nicer" syntax (I don't like it!) wasn't being interpreted correctly. See testRuntimeSpecialParamspecLiteralSyntax .

This is more:tm: correct as shown by changes in test cases. I can't find
any issues that are closed by this though. From what I remember, this
was a followup fix for python#14903 in
order to fix some incorrect mypy-primer output.
@A5rocks
A5rocks marked this pull request as ready for review May 16, 2023 22:34
@github-actions

Copy link
Copy Markdown
Contributor

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

sublime_debugger (https://github.com/daveleroy/sublime_debugger)
- modules/ui/input.py:11: error: Cannot infer type of lambda  [misc]
- modules/ui/input.py:11: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[Any], Any]"; expected "Callable[[], Any]"  [arg-type]
- modules/dap/session.py:105: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[Any], Any]"; expected "Callable[[VarArg(Iterable[ExceptionBreakpointsFilter]), KwArg(Iterable[ExceptionBreakpointsFilter])], Any]"  [arg-type]
- modules/views/breakpoints.py:28: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[Any], None]"; expected "Callable[[VarArg(Iterable[ExceptionBreakpointsFilter]), KwArg(Iterable[ExceptionBreakpointsFilter])], Any]"  [arg-type]
- modules/views/sources.py:21: error: Cannot determine type of "on_session_sources_updated"  [has-type]
- modules/views/sources.py:22: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/views/modules.py:23: error: Cannot determine type of "on_session_modules_updated"  [has-type]
- modules/views/modules.py:24: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/views/debugger.py:24: error: Cannot determine type of "on_session_active"  [has-type]
- modules/views/debugger.py:25: error: Cannot determine type of "on_session_added"  [has-type]
- modules/views/debugger.py:27: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[], Any]"; expected "Callable[[VarArg(None), KwArg(None)], Any]"  [arg-type]
- modules/views/debugger.py:70: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/views/debugger.py:71: error: Cannot infer type of lambda  [misc]
- modules/views/debugger.py:71: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[], Any]"; expected "Callable[[VarArg(None), KwArg(None)], Any]"  [arg-type]
- modules/debugger_output_panel.py:21: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[], Any]"; expected "Callable[[VarArg(None), KwArg(None)], Any]"  [arg-type]
- modules/views/variables.py:33: error: Cannot determine type of "on_session_variables_updated"  [has-type]
- modules/views/variables.py:34: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/debugger.py:78: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:79: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:80: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:82: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:83: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:84: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:85: error: Incompatible types in assignment (expression has type "Event[Session]", base class "Debugger" defined the type as "Event[[Session]]")  [assignment]
- modules/debugger.py:87: error: Type application has too many types (1 expected)  [misc]
- modules/debugger.py:116: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[str], Future[None]]"; expected "Callable[[VarArg(str), KwArg(str)], Any]"  [arg-type]
- modules/debugger.py:117: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[SourceLocation], Any]"; expected "Callable[[VarArg(SourceLocation), KwArg(SourceLocation)], Any]"  [arg-type]
- modules/debugger.py:131: error: Argument 1 to "add" of "Event" has incompatible type "Callable[[], Any]"; expected "Callable[[VarArg(None), KwArg(None)], Any]"  [arg-type]
- modules/debugger.py:145: error: Cannot determine type of "on_session_active"  [has-type]
- modules/debugger.py:146: error: Cannot determine type of "on_session_added"  [has-type]
- modules/debugger.py:147: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/debugger.py:347: error: Cannot determine type of "on_session_active"  [has-type]
- modules/debugger.py:353: error: Cannot determine type of "on_session_modules_updated"  [has-type]
- modules/debugger.py:356: error: Cannot determine type of "on_session_sources_updated"  [has-type]
- modules/debugger.py:359: error: Cannot determine type of "on_session_variables_updated"  [has-type]
- modules/debugger.py:362: error: Cannot determine type of "on_session_threads_updated"  [has-type]
- modules/debugger.py:370: error: Cannot determine type of "on_session_added"  [has-type]
- modules/debugger.py:371: error: Cannot determine type of "on_session_active"  [has-type]
- modules/debugger.py:393: error: Cannot determine type of "on_session_active"  [has-type]
- modules/debugger.py:395: error: Cannot determine type of "on_session_removed"  [has-type]
- modules/debugger.py:472: error: Cannot determine type of "on_session_active"  [has-type]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/converters.py:242: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "special_converters"  [union-attr]
+ steam/ext/commands/converters.py:242: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "special_converters"  [union-attr]
- steam/ext/commands/converters.py:242: error: Item "CallbackType[Any]" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "special_converters"  [union-attr]
+ steam/ext/commands/converters.py:242: error: Item "CallbackType[[Any]]" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "special_converters"  [union-attr]
- steam/ext/commands/converters.py:242: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__special_converters__"  [union-attr]
+ steam/ext/commands/converters.py:242: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__special_converters__"  [union-attr]
- steam/ext/commands/converters.py:245: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "special_converters"  [union-attr]
+ steam/ext/commands/converters.py:245: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "special_converters"  [union-attr]
- steam/ext/commands/converters.py:245: error: Item "CallbackType[Any]" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "special_converters"  [union-attr]
+ steam/ext/commands/converters.py:245: error: Item "CallbackType[[Any]]" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "special_converters"  [union-attr]
- steam/ext/commands/converters.py:247: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__special_converters__"  [union-attr]
+ steam/ext/commands/converters.py:247: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__special_converters__"  [union-attr]
+ steam/ext/commands/commands.py:732: error: Overloaded function implementation cannot satisfy signature 1 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:732: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:801: error: Overloaded function implementation cannot satisfy signature 1 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:801: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:907: error: Overloaded function implementation cannot satisfy signature 1 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:907: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:907: error: Overloaded function implementation cannot satisfy signature 3 due to inconsistencies in how they use type variables  [misc]
- steam/ext/commands/commands.py:935: error: Argument 1 to "Command" has incompatible type "CallT"; expected "CallbackType[Any]"  [arg-type]
+ steam/ext/commands/commands.py:935: error: Argument 1 to "Command" has incompatible type "CallT"; expected "CallbackType[[Any]]"  [arg-type]
+ steam/ext/commands/commands.py:974: error: Overloaded function implementation cannot satisfy signature 1 due to inconsistencies in how they use type variables  [misc]
+ steam/ext/commands/commands.py:974: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables  [misc]
- steam/ext/commands/commands.py:998: note:     def [C <: Command[Any]] command(*, name: str | None = ..., cls: type[C] | None = ..., help: str | None = ..., brief: str | None = ..., usage: str | None = ..., description: str | None = ..., aliases: Iterable[str] | None = ..., checks: list[CheckReturnType] = ..., cooldown: list[Cooldown[Any]] = ..., special_converters: list[type[ConverterBase[Any]] | type[BasicConverter[Any]]] = ..., cog: Cog | None = ..., parent: Command[Any] | None = ..., enabled: bool = ..., hidden: bool = ..., case_insensitive: bool = ...) -> Callable[[Callable[P, Coroutine[Any, Any, Any]]], Command[P]]
+ steam/ext/commands/commands.py:998: note:     def [C <: Command[[Any]]] command(*, name: str | None = ..., cls: type[C] | None = ..., help: str | None = ..., brief: str | None = ..., usage: str | None = ..., description: str | None = ..., aliases: Iterable[str] | None = ..., checks: list[CheckReturnType] = ..., cooldown: list[Cooldown[Any]] = ..., special_converters: list[type[ConverterBase[Any]] | type[BasicConverter[Any]]] = ..., cog: Cog | None = ..., parent: Command[Any] | None = ..., enabled: bool = ..., hidden: bool = ..., case_insensitive: bool = ...) -> Callable[[Callable[P, Coroutine[Any, Any, Any]]], Command[P]]
- steam/ext/commands/commands.py:1033: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__commands_checks__"  [union-attr]
+ steam/ext/commands/commands.py:1033: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__commands_checks__"  [union-attr]
- steam/ext/commands/commands.py:1035: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__commands_checks__"  [union-attr]
+ steam/ext/commands/commands.py:1035: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__commands_checks__"  [union-attr]
- steam/ext/commands/commands.py:1053: note: Consider using the upper bound "CommandDeco | Callable[..., Command[Any]] | CallbackType[Any]" instead
+ steam/ext/commands/commands.py:1053: note: Consider using the upper bound "CommandDeco | Callable[..., Command[[Any]]] | CallbackType[[Any]]" instead
- steam/ext/commands/commands.py:1084: note: Consider using the upper bound "CommandDeco | Callable[..., Command[Any]] | CallbackType[Any]" instead
+ steam/ext/commands/commands.py:1084: note: Consider using the upper bound "CommandDeco | Callable[..., Command[[Any]]] | CallbackType[[Any]]" instead
- steam/ext/commands/commands.py:1138: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__commands_cooldown__"  [union-attr]
+ steam/ext/commands/commands.py:1138: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__commands_cooldown__"  [union-attr]
- steam/ext/commands/commands.py:1139: error: Item "function" of the upper bound "Callable[..., Command[Any]] | CallbackType[Any]" of type variable "MC" has no attribute "__commands_cooldown__"  [union-attr]
+ steam/ext/commands/commands.py:1139: error: Item "function" of the upper bound "Callable[..., Command[[Any]]] | CallbackType[[Any]]" of type variable "MC" has no attribute "__commands_cooldown__"  [union-attr]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant