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 bug that results in false negative when a parameter is used wit… #9751

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

erictraut
Copy link
Collaborator

…hin a type expression and the parameter's type is a TypeVar or Self. This addresses #9750.

…hin a type expression and the parameter's type is a TypeVar or Self. This addresses #9750.
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_matchpy_connector.py:120:18 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:120:18 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:120:70 - error: Argument of type "list[Unequality | Unknown | Equality | Relational]" cannot be assigned to parameter "conditions_nonfalse" of type "List[Expr]" in function "add"
-     Type "Unequality | Unknown | Equality | Relational" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Relational" is not assignable to "Expr"
-     Type "Unequality | Unknown | Equality | Relational" is not assignable to type "Expr"
-       "Relational" is not assignable to "Expr"
-     Type "Unequality | Unknown | Equality | Relational" is not assignable to type "Expr"
-       "Relational" is not assignable to "Expr"
-     Type "Unequality | Unknown | Equality | Relational" is not assignable to type "Expr"
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:123:18 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:120:70 - error: Argument of type "list[Unequality | Integer]" cannot be assigned to parameter "conditions_nonfalse" of type "List[Expr]" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Unequality | Integer" is not assignable to type "Expr"
+       "Unequality" is not assignable to "Expr"
+     Type "Unequality | Integer" is not assignable to type "Expr"
+       "Unequality" is not assignable to "Expr"
+     Type "Unequality | Integer" is not assignable to type "Expr"
+       "Unequality" is not assignable to "Expr"
+     Type "Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Unequality" is not assignable to "Expr" (reportArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:123:18 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:126:9 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:126:9 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:132:9 - error: Argument of type "Equality | Unknown" cannot be assigned to parameter "expr" of type "Expr" in function "add"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_matchpy_connector.py:132:9 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer" cannot be assigned to parameter "expr" of type "Expr" in function "add"
-     Type "Equality | Unknown" is not assignable to type "Expr"
+     Type "Equality | Unknown | Relational | Unequality | Integer" is not assignable to type "Expr"
-       "Equality" is not assignable to "Expr" (reportArgumentType)
+       "Relational" is not assignable to "Expr" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:895:12 - error: Operator "/" not supported for types "Equality | Unknown" and "Literal[2]"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:895:12 - error: Operator "/" not supported for types "Equality | Unknown | Relational | Unequality | Integer" and "Literal[2]"
+     Operator "/" not supported for types "Equality" and "Literal[2]"
+     Operator "/" not supported for types "Relational" and "Literal[2]"
-     Operator "/" not supported for types "Equality" and "Literal[2]" (reportOperatorIssue)
+     Operator "/" not supported for types "Unequality" and "Literal[2]" (reportOperatorIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1863:12 - error: Cannot access attribute "combsimp" for class "Relational"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1863:12 - error: Cannot access attribute "combsimp" for class "Unequality"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
+     Attribute "factor" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1911:14 - error: Cannot access attribute "factor" for class "Relational"
+     Attribute "factor" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1911:14 - error: Cannot access attribute "factor" for class "Unequality"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1918:14 - error: Cannot access attribute "combsimp" for class "Relational"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1918:14 - error: Cannot access attribute "combsimp" for class "Unequality"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1932:12 - error: Cannot access attribute "combsimp" for class "Relational"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1932:12 - error: Cannot access attribute "combsimp" for class "Unequality"
+     Attribute "combsimp" is unknown (reportAttributeAccessIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1992:22 - error: Argument of type "Equality | Unknown | NaN | Sum" cannot be assigned to parameter "x" of type "ConvertibleToFloat" in function "__new__"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1992:22 - error: Argument of type "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum" cannot be assigned to parameter "x" of type "ConvertibleToFloat" in function "__new__"
-     Type "Equality | Unknown | NaN | Sum" is not assignable to type "ConvertibleToFloat"
+     Type "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum" is not assignable to type "ConvertibleToFloat"
-       Type "Equality" is not assignable to type "ConvertibleToFloat"
+       Type "Relational" is not assignable to type "ConvertibleToFloat"
-         "Equality" is not assignable to "str"
+         "Relational" is not assignable to "str"
-         "Equality" is incompatible with protocol "Buffer"
+         "Relational" is incompatible with protocol "Buffer"
-         "Equality" is incompatible with protocol "SupportsFloat"
+         "Relational" is incompatible with protocol "SupportsFloat"
-         "Equality" is incompatible with protocol "SupportsIndex"
+         "Relational" is incompatible with protocol "SupportsIndex"
+     Attribute "gammasimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2074:56 - error: Cannot access attribute "gammasimp" for class "Relational"
+     Attribute "gammasimp" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2074:56 - error: Cannot access attribute "gammasimp" for class "Unequality"
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2973:37 - error: Operator "*" not supported for types "Literal[2]" and "Equality | Unknown | NaN | Sum"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2973:37 - error: Operator "*" not supported for types "Literal[2]" and "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum"
+     Operator "*" not supported for types "Literal[2]" and "Equality"
+     Operator "*" not supported for types "Literal[2]" and "Relational"
-     Operator "*" not supported for types "Literal[2]" and "Equality" (reportOperatorIssue)
+     Operator "*" not supported for types "Literal[2]" and "Unequality" (reportOperatorIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2978:17 - error: Operator "*" not supported for types "Literal[2]" and "Equality | Unknown | NaN | Sum"
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:2978:17 - error: Operator "*" not supported for types "Literal[2]" and "Equality | Unknown | Relational | Unequality | Integer | NaN | Sum"
+     Operator "*" not supported for types "Literal[2]" and "Equality"
+     Operator "*" not supported for types "Literal[2]" and "Relational"

... (truncated 61 lines) ...

Tanjun (https://github.com/FasterSpeeding/Tanjun)
-   /tmp/mypy_primer/projects/Tanjun/tanjun/annotations.py:2206:16 - warning: Return type, "Unknown | type[_T@__getitem__]", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/Tanjun/tanjun/annotations.py:2206:16 - warning: Return type is unknown (reportUnknownVariableType)
-     Argument type is "type[Unknown] | type[object]*" (reportUnknownArgumentType)
+     Argument type is "type[Unknown]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/Tanjun/tanjun/annotations.py:2206:64 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:722:9 - error: Type of parameter "nope" is unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:722:32 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:723:9 - error: Type of parameter "boo" is unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:723:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:788:34 - error: Type of parameter "nom" is unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:788:56 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations.py:794:41 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "command" in function "with_annotated_args"
+     Argument type is "SlashCommand[(ctx: Context, nom: Unknown) -> Coroutine[Any, Any, None]]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations_future_annotations.py:590:9 - error: Type of parameter "nope" is unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations_future_annotations.py:590:32 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations_future_annotations.py:591:9 - error: Type of parameter "boo" is unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/Tanjun/tests/test_annotations_future_annotations.py:591:31 - error: Variable not allowed in type expression (reportInvalidTypeForm)
- 2473 errors, 6716 warnings, 0 informations 
+ 2484 errors, 6717 warnings, 0 informations 

@erictraut erictraut merged commit 07ef416 into main Jan 23, 2025
18 checks passed
@erictraut erictraut deleted the issue-9750 branch January 25, 2025 21:42
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