mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Add special handling for typing.get_args

Open Jordandev678 opened this issue 1 year ago • 6 comments

This PR adds special handling for typing.get_args when the input is a Union[Literal...] allowing it to return that type instead of the current behavior of returning Any. Adds the handling and related test cases for get_args with varying types.

This allows mypy to understand when it is used as a type guard.

from typing import Literal, get_args
type_alpha = Literal["a", "b", "c"]
strIn: str = "c"
if strIn in get_args(type_alpha):
    reveal_type(strIn)  # N: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]"
else:
    reveal_type(strIn)  # N: Revealed type is "builtins.str"

Fixes #15106

Jordandev678 avatar Sep 18 '24 18:09 Jordandev678

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

pydantic (https://github.com/pydantic/pydantic)
+ pydantic/v1/typing.py:180: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.2af4660a0e1d3f26a6bd9adf1a7fd475ec388a37
+ pydantic/v1/typing.py:180: : note: use --pdb to drop into pdb
- pydantic/v1/typing.py:50: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/typing.py:159: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/typing.py:254: error: Module has no attribute "_GenericAlias"  [attr-defined]
- pydantic/v1/validators.py:539: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/validators.py:614: error: No overload variant of "NamedTuple" matches argument type "dict[str, Any]"  [call-overload]
- pydantic/v1/validators.py:614: note: Possible overload variants:
- pydantic/v1/validators.py:614: note:     def __init__(self, str, Iterable[tuple[str, Any]], /) -> NamedTupleT
- pydantic/v1/validators.py:614: note:     def __init__(self, str, None = ..., /, **kwargs: Any) -> NamedTupleT
- pydantic/v1/color.py:199: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/class_validators.py:282: error: Function "f" could always be true in boolean context  [truthy-function]
- pydantic/v1/types.py:309: error: Incompatible default for argument "gt" (default has type "None", argument has type "float")  [assignment]
- pydantic/v1/types.py:309: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:309: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:310: error: Incompatible default for argument "ge" (default has type "None", argument has type "float")  [assignment]
- pydantic/v1/types.py:310: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:310: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:311: error: Incompatible default for argument "lt" (default has type "None", argument has type "float")  [assignment]
- pydantic/v1/types.py:311: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:311: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:312: error: Incompatible default for argument "le" (default has type "None", argument has type "float")  [assignment]
- pydantic/v1/types.py:312: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:312: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:313: error: Incompatible default for argument "multiple_of" (default has type "None", argument has type "float")  [assignment]
- pydantic/v1/types.py:313: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:313: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:486: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/types.py:528: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/types.py:575: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/types.py:624: error: Incompatible default for argument "unique_items" (default has type "None", argument has type "bool")  [assignment]
- pydantic/v1/types.py:624: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:624: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:704: error: Unsupported operand types for >= ("Literal['n']" and "int")  [operator]
- pydantic/v1/types.py:704: error: Unsupported operand types for >= ("Literal['N']" and "int")  [operator]
- pydantic/v1/types.py:704: error: Unsupported operand types for >= ("Literal['F']" and "int")  [operator]
- pydantic/v1/types.py:704: note: Left operand is of type "Literal['n', 'N', 'F'] | int"
- pydantic/v1/types.py:706: error: Unsupported operand types for + ("int" and "Literal['n']")  [operator]
- pydantic/v1/types.py:706: error: Unsupported operand types for + ("int" and "Literal['N']")  [operator]
- pydantic/v1/types.py:706: error: Unsupported operand types for + ("int" and "Literal['F']")  [operator]
- pydantic/v1/types.py:706: note: Right operand is of type "Literal['n', 'N', 'F'] | int"
- pydantic/v1/types.py:714: error: Argument 1 to "abs" has incompatible type "Literal['n', 'N', 'F'] | int"; expected "SupportsAbs[int]"  [arg-type]
- pydantic/v1/types.py:715: error: Argument 1 to "abs" has incompatible type "Literal['n', 'N', 'F'] | int"; expected "SupportsAbs[int]"  [arg-type]
- pydantic/v1/types.py:718: error: Argument 1 to "abs" has incompatible type "Literal['n', 'N', 'F'] | int"; expected "SupportsAbs[int]"  [arg-type]
- pydantic/v1/types.py:737: error: Incompatible default for argument "gt" (default has type "None", argument has type "Decimal")  [assignment]
- pydantic/v1/types.py:737: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:737: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:738: error: Incompatible default for argument "ge" (default has type "None", argument has type "Decimal")  [assignment]
- pydantic/v1/types.py:738: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:738: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:739: error: Incompatible default for argument "lt" (default has type "None", argument has type "Decimal")  [assignment]
- pydantic/v1/types.py:739: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:739: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:740: error: Incompatible default for argument "le" (default has type "None", argument has type "Decimal")  [assignment]
- pydantic/v1/types.py:740: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:740: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:743: error: Incompatible default for argument "multiple_of" (default has type "None", argument has type "Decimal")  [assignment]
- pydantic/v1/types.py:743: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:743: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:1198: error: Incompatible default for argument "gt" (default has type "None", argument has type "date")  [assignment]
- pydantic/v1/types.py:1198: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:1198: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:1199: error: Incompatible default for argument "ge" (default has type "None", argument has type "date")  [assignment]
- pydantic/v1/types.py:1199: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:1199: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:1200: error: Incompatible default for argument "lt" (default has type "None", argument has type "date")  [assignment]
- pydantic/v1/types.py:1200: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:1200: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/types.py:1201: error: Incompatible default for argument "le" (default has type "None", argument has type "date")  [assignment]
- pydantic/v1/types.py:1201: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/types.py:1201: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- pydantic/v1/networks.py:237: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/networks.py:237: error: Unsupported type "dict[str, str]" for ** expansion in TypedDict  [typeddict-item]
- pydantic/v1/networks.py:237: note: Error code "typeddict-item" not covered by "type: ignore" comment
- pydantic/v1/networks.py:680: error: Unused "type: ignore" comment  [unused-ignore]
- pydantic/v1/parse.py:18: error: Incompatible default for argument "content_type" (default has type "None", argument has type "str")  [assignment]
- pydantic/v1/parse.py:18: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- pydantic/v1/parse.py:18: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase

... (truncated 464 lines) ...

artigraph (https://github.com/artigraph/artigraph)
- Warning: unused section(s) in pyproject.toml: module = ['sh']
+ src/arti/internal/type_hints.py:42: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.2af4660a0e1d3f26a6bd9adf1a7fd475ec388a37
+ src/arti/internal/type_hints.py:42: : note: use --pdb to drop into pdb
- src/arti/internal/type_hints.py:54: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>")  [comparison-overlap]
- src/arti/internal/type_hints.py:55: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>")  [comparison-overlap]
- src/arti/internal/type_hints.py:104: error: Returning Any from function declared to return "tuple[type, ...]"  [no-any-return]
- src/arti/internal/dispatch.py:17: error: Class cannot subclass value of type "Any"  [misc]
- src/arti/internal/dispatch.py:37: error: Returning Any from function declared to return "Callable[..., RETURN]"  [no-any-return]
- src/arti/internal/dispatch.py:42: error: Unused "type: ignore" comment  [unused-ignore]
- src/arti/internal/mappings.py:14: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:14: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:15: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:15: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:16: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:16: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:21: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:21: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:27: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:33: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:33: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:33: error: "frozendict" expects no type arguments, but 2 given  [type-arg]
- src/arti/internal/mappings.py:47: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:47: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:61: error: Variable "K" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:61: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:61: error: Variable "V" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:64: error: Name "K" is not defined  [name-defined]
- src/arti/internal/mappings.py:64: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:76: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:76: error: The type "type[TypedBox]" is not generic and not indexable  [misc]
- src/arti/internal/mappings.py:76: error: Name "TypedBox" is used before definition  [used-before-def]
- src/arti/internal/mappings.py:79: error: Name "InputContainer" is used before definition  [used-before-def]
- src/arti/internal/mappings.py:80: error: Variable "arti.internal.mappings.InputElement" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:80: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:94: error: Variable "arti.internal.mappings.TypedNode" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:94: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:94: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:100: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:103: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:119: error: Variable "arti.internal.mappings.InputElement" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:119: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:125: error: Variable "arti.internal.mappings.TypedNode" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:125: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:125: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:132: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:145: error: Variable "arti.internal.mappings.TypedNode" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:145: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:145: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:148: error: Returning Any from function declared to return "TypedNode?[Any]"  [no-any-return]
- src/arti/internal/mappings.py:152: error: "TypedBox" expects no type arguments, but 1 given  [type-arg]
- src/arti/internal/mappings.py:152: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:157: error: "TypedBox" expects no type arguments, but 1 given  [type-arg]
- src/arti/internal/mappings.py:157: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:170: error: Variable "arti.internal.mappings.TypedNode" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:170: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:170: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:176: error: Variable "arti.internal.mappings.TypedNode" is not valid as a type  [valid-type]
- src/arti/internal/mappings.py:176: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
- src/arti/internal/mappings.py:176: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:179: error: Returning Any from function declared to return "TypedNode?[Any]"  [no-any-return]
- src/arti/internal/mappings.py:198: error: Unsupported target for indexed assignment ("TypedNode?[Any]")  [index]
- src/arti/internal/mappings.py:221: error: Function is missing a type annotation  [no-untyped-def]
- src/arti/internal/mappings.py:233: error: Name "V" is not defined  [name-defined]
- src/arti/internal/mappings.py:240: error: "TypedNode?[Any]" has no attribute "walk"  [attr-defined]
- src/arti/internal/mappings.py:253: error: Name "cls.__target_type__" is not defined  [name-defined]
- src/arti/fingerprints/__init__.py:82: error: Returning Any from function declared to return "bool"  [no-any-return]
- src/arti/internal/models.py:55: error: Unsupported dynamic base class "type"  [misc]
- src/arti/internal/models.py:146: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
- src/arti/internal/models.py:150: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
- src/arti/internal/models.py:199: error: Name "T" is not defined  [name-defined]
- src/arti/internal/models.py:203: error: Name "T" is not defined  [name-defined]
- src/arti/internal/models.py:204: error: Name "T" is not defined  [name-defined]
- src/arti/versions/__init__.py:17: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:21: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:31: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/versions/__init__.py:75: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/statistics/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/annotations/__init__.py:8: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:26: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:44: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:48: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:61: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:70: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- src/arti/types/__init__.py:74: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]

... (truncated 428 lines) ...

bokeh (https://github.com/bokeh/bokeh)
- Warning: unused section(s) in pyproject.toml: module = ['tests.*', 'tests.codebase.*', 'tests.support.defaults', 'tests.test_bokehjs', 'tests.test_cross', 'tests.test_defaults', 'tests.test_examples', 'tests.unit.bokeh.document.test_callbacks__document', 'tests.unit.bokeh.embed.test_standalone', 'tests.unit.bokeh.test_layouts__typing']
+ src/bokeh/core/property/enum.py:78: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.2af4660a0e1d3f26a6bd9adf1a7fd475ec388a37
+ src/bokeh/core/property/enum.py:78: : note: use --pdb to drop into pdb
- src/bokeh/io/export.py: note: In function "get_screenshot_as_png":
- src/bokeh/io/export.py:223:1: error: Return type becomes "Any" due to an unfollowed import  [no-any-unimported]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 102, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 186, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1183, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2420, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 589, in accept
+     return visitor.visit_overloaded_func_def(self)
+   File "/checker.py", line 629, in visit_overloaded_func_def
+     self._visit_overloaded_func_def(defn)
+   File "/checker.py", line 657, in _visit_overloaded_func_def
+     defn.impl.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1123, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1355, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1532, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4653, in visit_if_stmt
+     self.accept(s.else_body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1532, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4653, in visit_if_stmt
+     self.accept(s.else_body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1532, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4653, in visit_if_stmt
+     self.accept(s.else_body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1351, in accept
+     return visitor.visit_assignment_stmt(self)
+   File "/checker.py", line 2934, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3081, in check_assignment
+     rvalue_type, lvalue_type, infer_lvalue_type = self.check_member_assignment(
+   File "/checker.py", line 4359, in check_member_assignment
+     rvalue_type = self.check_simple_assignment(get_type, rvalue, context)
+   File "/checker.py", line 4271, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+   File "/checkexpr.py", line 5870, in accept
+     typ = node.accept(self)
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+   File "/checkexpr.py", line 652, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+   File "/checkexpr.py", line 1505, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+   File "/checkexpr.py", line 1599, in check_call
+     return self.check_callable_call(
+   File "/checkexpr.py", line 1749, in check_callable_call
+     formal_to_actual = map_actuals_to_formals(
+   File "/argmap.py", line 55, in map_actuals_to_formals
+     actualt = get_proper_type(actual_arg_type(ai))
+   File "/checkexpr.py", line 1754, in <lambda>
+     lambda i: self.accept(args[i]),
+   File "/checkexpr.py", line 5870, in accept
+     typ = node.accept(self)
+           ^^^^^^^^^^^^^^^^^
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 564, in visit_call_expr_inner
+     if node:
+        ^^^^
+ UnboundLocalError: cannot access local variable 'node' where it is not associated with a value

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/typehints.py:129: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.2af4660a0e1d3f26a6bd9adf1a7fd475ec388a37
+ koda_validate/typehints.py:129: : note: use --pdb to drop into pdb
- koda_validate/signature.py:82: error: Argument 1 to "DataclassValidator" has incompatible type "DataclassInstance | type[DataclassInstance]"; expected "type[Any]"  [arg-type]
- koda_validate/signature.py:82: error: Argument 1 to "dataclass_no_coerce" has incompatible type "DataclassInstance | type[DataclassInstance]"; expected "type[DataclassInstance]"  [arg-type]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 102, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 186, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1123, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1355, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1532, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4653, in visit_if_stmt
+     self.accept(s.else_body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)

... (truncated 1148 lines) ...```

github-actions[bot] avatar Sep 18 '24 19:09 github-actions[bot]

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

artigraph (https://github.com/artigraph/artigraph)
- Warning: unused section(s) in pyproject.toml: module = ['sh']
+ tests/arti/types/test_python_adapters.py:81: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.44288041f0beb742573db9acecee473a5b3dbf57
+ tests/arti/types/test_python_adapters.py:81: : note: use --pdb to drop into pdb
+ src/arti/internal/type_hints.py:136: error: Need type annotation for "hints" (hint: "hints: list[<type>] = ...")  [var-annotated]
+ src/arti/types/python.py:145: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
- src/arti/types/python.py:158: error: Argument "items" has incompatible type "tuple[Any, ...]"; expected "frozenset[Any]"  [arg-type]
+ src/arti/types/python.py:158: error: Argument "items" has incompatible type "tuple[Any]"; expected "frozenset[Any]"  [arg-type]
+ src/arti/types/python.py:167: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
+ src/arti/types/python.py:183: error: Need more than 1 value to unpack (2 expected)  [misc]
- tests/arti/types/test_python_adapters.py:86: error: Argument "items" to "Enum" has incompatible type "tuple[int, int, int]"; expected "frozenset[Any]"  [arg-type]
- tests/arti/types/test_python_adapters.py:92: error: Argument "items" to "Enum" has incompatible type "tuple[float, float]"; expected "frozenset[Any]"  [arg-type]
- tests/arti/types/test_python_adapters.py:95: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/types/test_python_adapters.py:98: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/types/test_python_adapters.py:137: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/types/test_python_adapters.py:137: error: Argument "items" to "Enum" has incompatible type "tuple[int, int, int]"; expected "frozenset[Any]"  [arg-type]
- tests/arti/types/test_python_adapters.py:137: note: Error code "arg-type" not covered by "type: ignore" comment
- tests/arti/types/test_pydantic_adapters.py:30: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
- tests/arti/types/test_pydantic_adapters.py:31: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
- tests/arti/types/test_pydantic_adapters.py:32: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
- tests/arti/types/test_pydantic_adapters.py:33: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
- tests/arti/types/test_pydantic_adapters.py:39: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
- tests/arti/types/test_pydantic_adapters.py:64: error: Value of type "FrozenMapping?[builtins.str, arti.types.Type]" is not indexable  [index]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 102, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 186, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1123, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1355, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2886, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1477, in accept
+     return visitor.visit_assert_stmt(self)
+   File "/checker.py", line 4686, in visit_assert_stmt
+     self.expr_checker.accept(s.expr)
+   File "/checkexpr.py", line 5870, in accept
+     typ = node.accept(self)
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+   File "/checkexpr.py", line 652, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+   File "/checkexpr.py", line 1505, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+   File "/checkexpr.py", line 1599, in check_call
+     return self.check_callable_call(
+   File "/checkexpr.py", line 1809, in check_callable_call
+     arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+   File "/checkexpr.py", line 1983, in infer_arg_types_in_context
+     res[ai] = self.accept(args[ai], arg_type)
+   File "/checkexpr.py", line 5870, in accept
+     typ = node.accept(self)
+   File "/nodes.py", line 2028, in accept
+     return visitor.visit_index_expr(self)
+   File "/checkexpr.py", line 4309, in visit_index_expr
+     result = self.visit_index_expr_helper(e)
+   File "/checkexpr.py", line 4324, in visit_index_expr_helper
+     left_type = self.accept(e.base)
+   File "/checkexpr.py", line 5870, in accept
+     typ = node.accept(self)
+           ^^^^^^^^^^^^^^^^^
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 566, in visit_call_expr_inner
+     typ = node.node.type
+           ^^^^^^^^^^^^^^
+ AttributeError: 'TypeInfo' object has no attribute 'type'
- tests/arti/storage/test_storage.py:25: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:32: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:32: error: "Storage" expects no type arguments, but 1 given  [type-arg]
- tests/arti/storage/test_storage.py:49: error: Argument "partition_key" to "MockStoragePartition" has incompatible type "dict[Never, Never]"; expected "PartitionKey"  [arg-type]
- tests/arti/storage/test_storage.py:57: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/storage/test_storage.py:57: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:57: note: Error code "misc" not covered by "type: ignore" comment
- tests/arti/storage/test_storage.py:64: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:64: error: "Storage" expects no type arguments, but 1 given  [type-arg]
- tests/arti/storage/test_storage.py:67: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:67: error: "Storage" expects no type arguments, but 1 given  [type-arg]
- tests/arti/storage/test_storage.py:71: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/storage/test_storage.py:148: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:155: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]
- tests/arti/storage/test_storage.py:155: error: "Storage" expects no type arguments, but 1 given  [type-arg]
- tests/arti/storage/test_local_storage.py:57: error: Unused "type: ignore" comment  [unused-ignore]
- tests/arti/storage/test_local_storage.py:132: error: Argument "partition_key" to "LocalFilePartition" has incompatible type "dict[Never, Never]"; expected "PartitionKey"  [arg-type]
- tests/arti/storage/test_literal_storage.py:25: error: Unexpected keyword argument "storage" for "StringLiteralPartition"  [call-arg]
- tests/arti/storage/test_literal_storage.py:28: error: Unexpected keyword argument "storage" for "StringLiteralPartition"  [call-arg]
- tests/arti/producers/test_producer.py:31: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases  [misc]

... (truncated 139 lines) ...

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/typehints.py:137: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:141: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/typehints.py:142: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:146: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/typehints.py:147: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:157: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:160: error: Need type annotation for "a"  [var-annotated]
+ koda_validate/typehints.py:190: error: Statement is unreachable  [unreachable]
+ koda_validate/signature.py:88: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/signature.py:89: error: Statement is unreachable  [unreachable]

ibis (https://github.com/ibis-project/ibis)
+ ibis/common/patterns.py:135: error: Need type annotation for "rest" (hint: "rest: list[<type>] = ...")  [var-annotated]
+ ibis/common/patterns.py:151: error: Need type annotation for "extras" (hint: "extras: list[<type>] = ...")  [var-annotated]
+ ibis/common/patterns.py:160: error: Need more than 1 value to unpack (2 expected)  [misc]

scipy (https://github.com/scipy/scipy)
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "fft_mode" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['twosided', 'centered', 'onesided', 'onesided2X']"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "mfft" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "scale_to" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['magnitude', 'psd'] | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "phase_shift" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_implementations.py:879: error: Tuple index out of range  [misc]
+ src/hydra_zen/structured_configs/_implementations.py:894: error: Incompatible types in assignment (expression has type "tuple[type, ...]", variable has type "tuple[Any]")  [assignment]

Expression (https://github.com/cognitedata/Expression)
+ expression/core/result.py:272: error: Incompatible types in assignment (expression has type "tuple[Any]", variable has type "tuple[<typing special form>, <typing special form>]")  [assignment]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/state.py:3040: error: Access to generic instance variables via class is ambiguous  [misc]
+ steam/ext/commands/commands.py:441: error: Need more than 1 value to unpack (2 expected)  [misc]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/proxy/mode_servers.py:103: error: Unused "type: ignore" comment  [unused-ignore]

github-actions[bot] avatar Sep 18 '24 19:09 github-actions[bot]

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

artigraph (https://github.com/artigraph/artigraph)
+ src/arti/internal/type_hints.py:136: error: Need type annotation for "hints" (hint: "hints: list[<type>] = ...")  [var-annotated]
+ src/arti/types/python.py:145: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
- src/arti/types/python.py:158: error: Argument "items" has incompatible type "tuple[Any, ...]"; expected "frozenset[Any]"  [arg-type]
+ src/arti/types/python.py:158: error: Argument "items" has incompatible type "tuple[Any]"; expected "frozenset[Any]"  [arg-type]
+ src/arti/types/python.py:167: error: Non-overlapping identity check (left operand type: "ParamSpec", right operand type: "<typing special form>")  [comparison-overlap]
+ src/arti/types/python.py:183: error: Need more than 1 value to unpack (2 expected)  [misc]
- tests/arti/internal/test_mappings.py:47: error: The type "type[frozendict]" is not generic and not indexable  [misc]
+ tests/arti/internal/test_mappings.py:47: error: Non-overlapping equality check (left operand type: "tuple[Any]", right operand type: "tuple[type[str], type[int]]")  [comparison-overlap]

koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/typehints.py:137: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:141: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/typehints.py:142: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:146: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/typehints.py:147: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:157: error: Statement is unreachable  [unreachable]
+ koda_validate/typehints.py:160: error: Need type annotation for "a"  [var-annotated]
+ koda_validate/typehints.py:190: error: Statement is unreachable  [unreachable]
+ koda_validate/signature.py:88: error: Right operand of "and" is never evaluated  [unreachable]
+ koda_validate/signature.py:89: error: Statement is unreachable  [unreachable]

ibis (https://github.com/ibis-project/ibis)
+ ibis/common/patterns.py:135: error: Need type annotation for "rest" (hint: "rest: list[<type>] = ...")  [var-annotated]
+ ibis/common/patterns.py:151: error: Need type annotation for "extras" (hint: "extras: list[<type>] = ...")  [var-annotated]
+ ibis/common/patterns.py:160: error: Need more than 1 value to unpack (2 expected)  [misc]

scipy (https://github.com/scipy/scipy)
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "fft_mode" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['twosided', 'centered', 'onesided', 'onesided2X']"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "mfft" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "scale_to" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['magnitude', 'psd'] | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "phase_shift" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_implementations.py:879: error: Tuple index out of range  [misc]
+ src/hydra_zen/structured_configs/_implementations.py:894: error: Incompatible types in assignment (expression has type "tuple[type, ...]", variable has type "tuple[Any]")  [assignment]

steam.py (https://github.com/Gobot1234/steam.py)
- steam/state.py:3040: error: Access to generic instance variables via class is ambiguous  [misc]
+ steam/ext/commands/commands.py:441: error: Need more than 1 value to unpack (2 expected)  [misc]

Expression (https://github.com/cognitedata/Expression)
+ expression/core/result.py:272: error: Incompatible types in assignment (expression has type "tuple[Any]", variable has type "tuple[<typing special form>, <typing special form>]")  [assignment]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/proxy/mode_servers.py:103: error: Unused "type: ignore" comment  [unused-ignore]

github-actions[bot] avatar Sep 18 '24 21:09 github-actions[bot]

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

scipy (https://github.com/scipy/scipy)
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "fft_mode" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['twosided', 'centered', 'onesided', 'onesided2X']"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "mfft" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "scale_to" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['magnitude', 'psd'] | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "phase_shift" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]

github-actions[bot] avatar Sep 19 '24 15:09 github-actions[bot]

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

scipy (https://github.com/scipy/scipy)
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "fft_mode" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['twosided', 'centered', 'onesided', 'onesided2X']"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:419: error: Argument "mfft" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "scale_to" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "Literal['magnitude', 'psd'] | None"  [arg-type]
+ scipy/signal/tests/test_short_time_fft.py:420: error: Argument "phase_shift" to "ShortTimeFFT" has incompatible type "str | int | None"; expected "int | None"  [arg-type]

github-actions[bot] avatar Sep 19 '24 16:09 github-actions[bot]

With respect to the primer results those errors seem fine.

 pp = dict(
        fft_mode=get_args(FFT_MODE_TYPE),
        mfft=[None, n, n+1, n+2],
        scaling=[None, 'magnitude', 'psd'],
        phase_shift=[None, -n+1, 0, n // 2, n-1])
    for f_typ, mfft, scaling, phase_shift in product(*pp.values()):
        if f_typ == 'onesided2X' and scaling is None:
            continue  # this combination is forbidden
        SFT = ShortTimeFFT(w, h_n, fs=n, fft_mode=f_typ, mfft=mfft,
                           scale_to=scaling, phase_shift=phase_shift)

#<snip from ShortTimeFFT definition>
   _fft_mode: FFT_MODE_TYPE = 'onesided'  # Mode of FFT to use

It's complaining fft_mode=f_typ isn't FFT_MODE_TYPE. By the time the get_args call makes it through the dict, values, and product calls to generate the test setups the result is str | int | None.

As for the other three related additions - they were only absent prior because before this get_args would have returned Any and with the Any in the mix it wouldn't have been type checked at all.

Worth someone else taking a look at this now.

Jordandev678 avatar Oct 09 '24 19:10 Jordandev678

Is there a reason this is still a draft?

flying-sheep avatar Aug 06 '25 12:08 flying-sheep