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

Improved type evaluation performance in certain cases involving proto… #9115

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

erictraut
Copy link
Collaborator

…col matching for complex, nested protocols. This addresses #9109.

…col matching for complex, nested protocols. This addresses #9109.
Copy link
Contributor

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

kopf (https://github.com/nolar/kopf)
- /tmp/mypy_primer/projects/kopf/kopf/_core/reactor/running.py
-   /tmp/mypy_primer/projects/kopf/kopf/_core/reactor/running.py:301:23 - error: Argument of type "partial[Coroutine[Any, Any, Response]]" cannot be assigned to parameter "webhookfn" of type "WebhookFn" in function "admission_webhook_server"
-     "partial[Coroutine[Any, Any, Response]]" is incompatible with protocol "WebhookFn"
-       "__call__" is an incompatible type
-         Type "(request: Request, ..., headers: Mapping[str, str] | None = ..., sslpeer: Mapping[str, Any] | None = ..., webhook: HandlerId | None = ..., reason: WebhookType | None = ..., settings: OperatorSettings = ..., memories: MemoGetter = ..., memobase: AnyMemo = ..., registry: OperatorRegistry = ..., insights: Insights = ..., indices: Indices = ...) -> Coroutine[Any, Any, Response]" is not assignable to type "(request: Request, *, webhook: str | None = None, headers: Mapping[str, str] | None = None, sslpeer: Mapping[str, Any] | None = None) -> Awaitable[Response]"
-           Keyword parameter "webhook" of type "str | None" is incompatible with type "HandlerId | None"
-             Type "str | None" is not assignable to type "HandlerId | None" (reportArgumentType)
- 1167 errors, 19 warnings, 0 informations 
+ 1166 errors, 19 warnings, 0 informations 

core (https://github.com/home-assistant/core)
+   /tmp/mypy_primer/projects/core/homeassistant/components/alexa/handlers.py:562:14 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/backup/manager.py:147:34 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/backup/manager.py:147:80 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/backup/manager.py:224:22 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/backup/manager.py:224:55 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/binary_sensor.py:565:31 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/binary_sensor.py:565:55 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+ /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/helpers.py
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/helpers.py:65:17 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/helpers.py:65:69 - error: Argument of type "Literal[1]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[1]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/helpers.py:66:17 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/bayesian/helpers.py:66:71 - error: Argument of type "Literal[1]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[1]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/coinbase/sensor.py:168:36 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/coinbase/sensor.py:171:17 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/daikin/climate.py:95:16 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/dovado/sensor.py:132:20 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/geonetnz_volcano/sensor.py:113:30 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/geonetnz_volcano/sensor.py:119:17 - error: Argument of type "Literal[1]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[1]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/number/__init__.py:400:59 - error: Argument of type "Overload[(number: _SupportsRound1[_T@round], ndigits: None = None) -> _T@round, (number: _SupportsRound2[_T@round], ndigits: SupportsIndex) -> _T@round]" cannot be assigned to parameter "method" of type "(float, int) -> float" in function "_convert_to_state_value"
+     No overloaded function matches type "(float, int) -> float" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/omnilogic/sensor.py:109:29 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/omnilogic/sensor.py:109:70 - error: Argument of type "Literal[1]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[1]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/overkiz/sensor.py:287:36 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/overkiz/sensor.py:287:62 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/overkiz/sensor.py:335:36 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/overkiz/sensor.py:335:62 - error: Argument of type "Literal[2]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[2]" is not assignable to "None" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/tellduslive/sensor.py:169:16 - error: No overloads for "round" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/tellduslive/sensor.py:169:42 - error: Argument of type "Literal[1]" cannot be assigned to parameter "ndigits" of type "None" in function "round"
+     "Literal[1]" is not assignable to "None" (reportArgumentType)
- 24344 errors, 347 warnings, 0 informations 
+ 24370 errors, 347 warnings, 0 informations 

pycryptodome (https://github.com/Legrandin/pycryptodome)
-   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Math/test_modexp.py:134:34 - error: Argument of type "IntegerBase" cannot be assigned to parameter "exp" of type "complex" in function "pow"
+   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Math/test_modexp.py:134:34 - error: Argument of type "IntegerBase" cannot be assigned to parameter "exp" of type "_E@pow" in function "pow"
-     "IntegerBase" is not assignable to "complex" (reportArgumentType)
+     "IntegerBase" is not assignable to "int" (reportArgumentType)
-   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Math/test_modexp.py:134:45 - error: Argument of type "IntegerBase" cannot be assigned to parameter "mod" of type "None" in function "pow"
+   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Math/test_modexp.py:134:45 - error: Argument of type "IntegerBase" cannot be assigned to parameter "mod" of type "_M@pow" in function "pow"
+     Type "IntegerBase" is not assignable to type "int | None"
+       "IntegerBase" is not assignable to "int"
-     "IntegerBase" is not assignable to "None" (reportArgumentType)
+       "IntegerBase" is not assignable to "None" (reportArgumentType)

spark (https://github.com/apache/spark)
-       "__next__" is not present (reportArgumentType)
+       "__next__" is not present
+         Could not bind method "__iter__" because "str" is not assignable to parameter "self"
+           "str" is not assignable to "LiteralString" (reportArgumentType)
-       "__next__" is not present (reportArgumentType)
+       "__next__" is not present
+         Could not bind method "__iter__" because "str" is not assignable to parameter "self"
+           "str" is not assignable to "LiteralString" (reportArgumentType)
+         Could not bind method "__iter__" because "str" is not assignable to parameter "self"
+           "str" is not assignable to "LiteralString"
-           No overloaded function matches type "() -> Iterator[_T_co@Iterator]" (reportArgumentType)
+           Type "() -> Iterator[str]" is not assignable to type "() -> Iterator[_T_co@Iterator]"
+             Function return type "Iterator[str]" is incompatible with type "Iterator[_T_co@Iterator]" (reportArgumentType)
+         Could not bind method "__iter__" because "str" is not assignable to parameter "self"
+           "str" is not assignable to "LiteralString"
-           No overloaded function matches type "() -> Iterator[_T_co@Iterator]" (reportArgumentType)
+           Type "() -> Iterator[str]" is not assignable to type "() -> Iterator[_T_co@Iterator]"
+             Function return type "Iterator[str]" is incompatible with type "Iterator[_T_co@Iterator]" (reportArgumentType)

jax (https://github.com/google/jax)
-   /tmp/mypy_primer/projects/jax/jax/_src/ad_checkpoint.py:836:33 - error: Argument of type "partial[Unknown | Sequence[IrValues]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | Sequence[IrValues]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, ..., jaxpr: Jaxpr, prevent_cse: bool, differentiated: bool, policy: Unknown, is_gpu_platform: bool = ...) -> (Unknown | Sequence[IrValues])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/prng.py:938:5 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, k1: Unknown, k2: Unknown, x1: Unknown, x2: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/prng.py:942:5 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, k1: Unknown, k2: Unknown, x1: Unknown, x2: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/interpreters/mlir.py:2117:32 - error: Argument of type "partial[list[IrValues]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[list[IrValues]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: LoweringRuleContext, ..., backend: Unknown | None = ..., call_jaxpr: Unknown, name: Unknown = ...) -> list[IrValues]" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/interpreters/mlir.py:2119:19 - error: Argument of type "partial[list[IrValues]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[list[IrValues]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: LoweringRuleContext, ..., backend: Unknown | None = ..., call_jaxpr: Unknown, name: Unknown = ...) -> list[IrValues]" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/ann.py:396:23 - error: Argument of type "partial[Unknown]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, operand: Unknown, ..., k: Unknown, reduction_dimension: Unknown, recall_target: Unknown, is_max_k: Unknown, reduction_input_size_override: Unknown, aggregate_to_topk: Unknown, fallback: bool = ...) -> Unknown" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/convolution.py:760:5 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, lhs: Unknown, rhs: Unknown, ..., window_strides: Unknown, padding: Unknown, lhs_dilation: Unknown, rhs_dilation: Unknown, dimension_numbers: Unknown, feature_group_count: Unknown, batch_group_count: Unknown, precision: Unknown, preferred_element_type: Unknown, expand_complex_convolutions: bool = ...) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/convolution.py:764:5 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, lhs: Unknown, rhs: Unknown, ..., window_strides: Unknown, padding: Unknown, lhs_dilation: Unknown, rhs_dilation: Unknown, dimension_numbers: Unknown, feature_group_count: Unknown, batch_group_count: Unknown, precision: Unknown, preferred_element_type: Unknown, expand_complex_convolutions: bool = ...) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/lax.py:2748:30 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, x: Unknown, y: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/lax.py:2752:30 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, x: Unknown, y: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/lax.py:2756:30 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, x: Unknown, y: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/lax.py:2760:30 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, x: Unknown, y: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter
-           Parameter "**kw" has no corresponding parameter (reportArgumentType)
-   /tmp/mypy_primer/projects/jax/jax/_src/lax/lax.py:2764:30 - error: Argument of type "partial[Unknown | list[Unknown]]" cannot be assigned to parameter "rule" of type "LoweringRule" in function "register_lowering"
-     "partial[Unknown | list[Unknown]]" is incompatible with protocol "LoweringRule"
-       "__call__" is an incompatible type
-         Type "(ctx: Unknown, x: Unknown, y: Unknown) -> (Unknown | list[Unknown])" is not assignable to type "(ctx: LoweringRuleContext, *args: Unknown | Sequence[Unknown], **kw: Unknown) -> Sequence[Unknown | Sequence[Unknown]]"
-           Parameter "*args" has no corresponding parameter

... (truncated 421 lines) ...

@erictraut erictraut merged commit 0b02230 into main Sep 30, 2024
18 checks passed
@erictraut erictraut deleted the issue-9109 branch September 30, 2024 21:30
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