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

Fixed a bug that results in incorrect type evaluation behaviors when … #9071

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

erictraut
Copy link
Collaborator

…a class has a custom metaclass with a __call__ method and a __new__ or __init__ method that provides a different bidirectional type inference context for parameters. This addresses #9067.

…a class has a custom metaclass with a `__call__` method and a `__new__` or `__init__` method that provides a different bidirectional type inference context for parameters. This addresses #9067.
Copy link
Contributor

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

ibis (https://github.com/ibis-project/ibis)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/bigquery/datatypes.py:67:27 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/bigquery/datatypes.py:67:27 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-       "int" is not assignable to type "Literal[5]" (reportArgumentType)
+       "int" is not assignable to type "Literal[5]"
+     ... (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/datafusion/__init__.py:542:13 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/datafusion/__init__.py:542:13 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/duckdb/__init__.py:311:13 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/duckdb/__init__.py:311:13 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/duckdb/__init__.py:1594:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/duckdb/__init__.py:1594:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Any, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/exasol/__init__.py:271:21 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/exasol/__init__.py:271:21 - error: Argument of type "dict[Unknown, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:262:9 - error: Argument of type "dict[str, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:262:9 - error: Argument of type "dict[str, Int32 | Boolean | Int16 | Int64 | Float32 | Float64 | String | Timestamp]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[str, Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:456:30 - error: Argument of type "dict[str, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:456:30 - error: Argument of type "dict[str, String | Int64 | Float64]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[str, Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:484:34 - error: Argument of type "dict[str, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:484:34 - error: Argument of type "dict[str, String | Int64]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[str, Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:486:24 - error: Argument of type "dict[str, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/flink/tests/test_ddl.py:486:24 - error: Argument of type "dict[str, String | Int64 | Float64]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[str, Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/polars/rewrites.py:33:13 - error: Argument of type "dict[Unknown, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/polars/rewrites.py:33:13 - error: Argument of type "dict[Unknown, Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/postgres/__init__.py:536:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/postgres/__init__.py:536:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Any, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/pyspark/datatypes.py:125:27 - error: Argument of type "dict[Unknown, Decimal | Array[Unknown] | Map[Unknown, Unknown] | Struct | Interval | Timestamp | Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/pyspark/datatypes.py:125:27 - error: Argument of type "dict[Unknown, Decimal | Array[Unknown] | Map[Unknown, Unknown] | Struct | Interval | Timestamp | Unknown]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Unknown, Decimal | Array[Unknown] | Map[Unknown, Unknown] | Struct | Interval | Timestamp | Unknown]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/snowflake/__init__.py:575:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/snowflake/__init__.py:575:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Any, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-   /tmp/mypy_primer/projects/ibis/ibis/backends/snowflake/__init__.py:591:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__"
+   /tmp/mypy_primer/projects/ibis/ibis/backends/snowflake/__init__.py:591:13 - error: Argument of type "dict[Any, DataType]" cannot be assigned to parameter "fields" of type "FrozenOrderedDict[str, DataType]" in function "__init__" (reportArgumentType)
-     "dict[Any, DataType]" is not assignable to "FrozenOrderedDict[str, DataType]" (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"
+     ... (reportArgumentType)
-         "int" is not assignable to type "Literal[4]" (reportArgumentType)
+         "int" is not assignable to type "Literal[4]"

... (truncated 254 lines) ...

@erictraut erictraut merged commit 399d57d into main Sep 24, 2024
18 checks passed
@erictraut erictraut deleted the issue-9067 branch September 24, 2024 22:16
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