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

Added support for argument type expansion of bool, enums, and tuples … #9763

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

erictraut
Copy link
Collaborator

…of fixed length when evaluating overloads. This behavior is mandated by the new draft typing spec update. This addresses #9706.

…of fixed length when evaluating overloads. This behavior is mandated by the new draft typing spec update. This addresses #9706.
Copy link
Contributor

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

sympy (https://github.com/sympy/sympy)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_lambdify.py:1125:28 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_lambdify.py:1138:29 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
-     Return type mismatch: base method returns type "tuple[Expr, Expr]", override returns type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Unknown, Unknown] | None"
-       Type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Unknown, Unknown] | None" is not assignable to type "tuple[Expr, Expr]"
+     Return type mismatch: base method returns type "tuple[Expr, Expr]", override returns type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Expr | Any | Unknown, Expr | Any | Unknown] | tuple[Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number, Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number] | None"
+       Type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Expr | Any | Unknown, Expr | Any | Unknown] | tuple[Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number, Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number] | None" is not assignable to type "tuple[Expr, Expr]"
-     Return type mismatch: base method returns type "tuple[Expr, Expr]", override returns type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Unknown, Unknown] | None"
-       Type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Unknown, Unknown] | None" is not assignable to type "tuple[Expr, Expr]"
+     Return type mismatch: base method returns type "tuple[Expr, Expr]", override returns type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Expr | Any | Unknown, Expr | Any | Unknown] | tuple[Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number, Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number] | None"
+       Type "tuple[Self@Mul, Zero] | tuple[Zero, Expr] | tuple[Expr, Expr] | tuple[Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType, Expr | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType] | tuple[Expr | Any | Unknown, Expr | Any | Unknown] | tuple[Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number, Expr | Any | Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number] | None" is not assignable to type "tuple[Expr, Expr]"
- 32998 errors, 73 warnings, 0 informations 
+ 33000 errors, 73 warnings, 0 informations 

prefect (https://github.com/PrefectHQ/prefect)
-     Type "(self: Self@Flow[P@Flow, R@Flow], *args: P@Flow.args, return_state: bool = False, wait_for: Iterable[PrefectFuture[Any]] | None = None, **kwargs: P@Flow.kwargs) -> (Unknown | R@Flow | State[Any] | Coroutine[Any, Any, R@Flow | State[Any] | None] | Generator[R@Flow, None, None] | AsyncGenerator[R@Flow, None] | None)" is not assignable to type "(self: Flow[P@Flow, Coroutine[Any, Any, T@__call__]], *args: P@Flow.args, return_state: Literal[True], **kwargs: P@Flow.kwargs) -> Awaitable[State[T@__call__]]"
+     Type "(self: Self@Flow[P@Flow, R@Flow], *args: P@Flow.args, return_state: bool = False, wait_for: Iterable[PrefectFuture[Any]] | None = None, **kwargs: P@Flow.kwargs) -> (Coroutine[Any, Any, Any] | Any | R@Flow | State[Any] | Coroutine[Any, Any, R@Flow | State[Any] | None] | Generator[R@Flow, None, None] | AsyncGenerator[R@Flow, None] | None)" is not assignable to type "(self: Flow[P@Flow, Coroutine[Any, Any, T@__call__]], *args: P@Flow.args, return_state: Literal[True], **kwargs: P@Flow.kwargs) -> Awaitable[State[T@__call__]]"
-     Type "(self: Self@Flow[P@Flow, R@Flow], *args: P@Flow.args, return_state: bool = False, wait_for: Iterable[PrefectFuture[Any]] | None = None, **kwargs: P@Flow.kwargs) -> (Unknown | R@Flow | State[Any] | Coroutine[Any, Any, R@Flow | State[Any] | None] | Generator[R@Flow, None, None] | AsyncGenerator[R@Flow, None] | None)" is not assignable to type "(self: Flow[P@Flow, T@__call__], *args: P@Flow.args, return_state: Literal[True], **kwargs: P@Flow.kwargs) -> State[T@__call__]"
+     Type "(self: Self@Flow[P@Flow, R@Flow], *args: P@Flow.args, return_state: bool = False, wait_for: Iterable[PrefectFuture[Any]] | None = None, **kwargs: P@Flow.kwargs) -> (Coroutine[Any, Any, Any] | Any | R@Flow | State[Any] | Coroutine[Any, Any, R@Flow | State[Any] | None] | Generator[R@Flow, None, None] | AsyncGenerator[R@Flow, None] | None)" is not assignable to type "(self: Flow[P@Flow, T@__call__], *args: P@Flow.args, return_state: Literal[True], **kwargs: P@Flow.kwargs) -> State[T@__call__]"
-   /tmp/mypy_primer/projects/prefect/src/prefect/flows.py:1388:20 - error: No overloads for "track_viz_task" match the provided arguments (reportCallIssue)
-   /tmp/mypy_primer/projects/prefect/src/prefect/flows.py:1388:35 - error: Argument of type "bool" cannot be assigned to parameter "is_async" of type "Literal[False]" in function "track_viz_task"
-     "bool" is not assignable to type "Literal[False]" (reportArgumentType)
-   /tmp/mypy_primer/projects/prefect/src/prefect/tasks.py:1029:20 - error: No overloads for "track_viz_task" match the provided arguments (reportCallIssue)
-   /tmp/mypy_primer/projects/prefect/src/prefect/tasks.py:1030:17 - error: Argument of type "bool" cannot be assigned to parameter "is_async" of type "Literal[False]" in function "track_viz_task"
-     "bool" is not assignable to type "Literal[False]" (reportArgumentType)
+   /tmp/mypy_primer/projects/prefect/src/prefect/tasks.py:1029:20 - error: Type "Coroutine[Any, Any, Any] | Any" is not assignable to return type "R@Task | State[R@Task] | None"
+     Type "Coroutine[Any, Any, Any] | Any" is not assignable to type "R@Task | State[R@Task] | None"
+       Type "Coroutine[Any, Any, Any]" is not assignable to type "R@Task | State[R@Task] | None"
+         Type "Coroutine[Any, Any, Any]" is not assignable to type "R@Task"
+         "Coroutine[Any, Any, Any]" is not assignable to "State[R@Task]"
+         "Coroutine[Any, Any, Any]" is not assignable to "None" (reportReturnType)
- 5553 errors, 276 warnings, 0 informations 
+ 5550 errors, 276 warnings, 0 informations 

xarray (https://github.com/pydata/xarray)
-   /tmp/mypy_primer/projects/xarray/xarray/core/utils.py:1047:26 - error: Argument of type "bool" cannot be assigned to parameter "replace_none" of type "Literal[False]" in function "parse_dims_as_tuple"
-     "bool" is not assignable to type "Literal[False]" (reportArgumentType)
-   /tmp/mypy_primer/projects/xarray/xarray/tests/test_distributed.py:265:31 - error: Argument of type "bool" cannot be assigned to parameter "compute" of type "Literal[False]" in function "to_zarr"
-     "bool" is not assignable to type "Literal[False]" (reportArgumentType)
+   /tmp/mypy_primer/projects/xarray/xarray/tests/test_distributed.py:268:27 - error: Cannot access attribute "compute" for class "ZarrStore"
+     Attribute "compute" is unknown (reportAttributeAccessIssue)
- 2473 errors, 93 warnings, 0 informations 
+ 2472 errors, 93 warnings, 0 informations 

urllib3 (https://github.com/urllib3/urllib3)
-   /tmp/mypy_primer/projects/urllib3/test/test_ssltransport.py:56:24 - error: No overloads for "sample_request" match the provided arguments (reportCallIssue)
-   /tmp/mypy_primer/projects/urllib3/test/test_ssltransport.py:56:39 - error: Argument of type "bool" cannot be assigned to parameter "binary" of type "Literal[False]" in function "sample_request"
-     "bool" is not assignable to type "Literal[False]" (reportArgumentType)
- 223 errors, 11 warnings, 0 informations 
+ 221 errors, 11 warnings, 0 informations 

jax (https://github.com/google/jax)
-   /tmp/mypy_primer/projects/jax/jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:221:10 - error: No overloads for "_attention_reference" match the provided arguments (reportCallIssue)
-   /tmp/mypy_primer/projects/jax/jax/experimental/pallas/ops/tpu/splash_attention/splash_attention_kernel.py:228:22 - error: Argument of type "bool" cannot be assigned to parameter "save_residuals" of type "Literal[True]" in function "_attention_reference"
-     "bool" is not assignable to type "Literal[True]" (reportArgumentType)
- 6555 errors, 28 warnings, 0 informations 
+ 6553 errors, 28 warnings, 0 informations 

@erictraut erictraut merged commit 4cae89f into main Jan 26, 2025
18 checks passed
@erictraut erictraut deleted the issue-9706 branch January 26, 2025 05:51
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