Skip to content

narrow unions on initial assignment#7

Draft
hauntsaninja wants to merge 1 commit intomasterfrom
narrow2008union
Draft

narrow unions on initial assignment#7
hauntsaninja wants to merge 1 commit intomasterfrom
narrow2008union

Conversation

@hauntsaninja
Copy link
Copy Markdown
Owner

No description provided.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 5, 2026

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

beartype (https://github.com/beartype/beartype)
+ beartype/claw/_ast/_kind/clawastimport.py:733: error: Unused "type: ignore" comment  [unused-ignore]
+ beartype/claw/_package/clawpkgtrie.py:567: error: Unused "type: ignore" comment  [unused-ignore]
+ beartype/claw/_package/clawpkgtrie.py:771: error: Unused "type: ignore" comment  [unused-ignore]

spark (https://github.com/apache/spark)
+ python/pyspark/ml/pipeline.py:440: error: Need type annotation for "stages" (hint: "stages: list[<type>] = ...")  [var-annotated]

tornado (https://github.com/tornadoweb/tornado)
+ tornado/http1connection.py:621: error: Redundant cast to "int"  [redundant-cast]

pydantic (https://github.com/pydantic/pydantic)
+ pydantic/_internal/_typing_extra.py:355: error: Invalid index type "str" for "dict[Never, Never]"; expected type "Never"  [index]
+ pydantic/_internal/_typing_extra.py:355: error: Incompatible types in assignment (expression has type "tuple[Any, bool]", target has type "Never")  [assignment]
+ pydantic/_internal/_typing_extra.py:357: error: Invalid index type "str" for "dict[Never, Never]"; expected type "Never"  [index]
+ pydantic/_internal/_typing_extra.py:357: error: Incompatible types in assignment (expression has type "tuple[Any, bool]", target has type "Never")  [assignment]
+ pydantic/_internal/_typing_extra.py:364: error: Invalid index type "str" for "dict[Never, Never]"; expected type "Never"  [index]
+ pydantic/_internal/_typing_extra.py:364: error: Incompatible types in assignment (expression has type "tuple[Any, bool]", target has type "Never")  [assignment]
+ pydantic/_internal/_typing_extra.py:368: error: Invalid index type "str" for "dict[Never, Never]"; expected type "Never"  [index]
+ pydantic/_internal/_typing_extra.py:368: error: Incompatible types in assignment (expression has type "tuple[Any, bool]", target has type "Never")  [assignment]

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/web_fileresponse.py:330:21: error: Statement is unreachable  [unreachable]
+ aiohttp/web_fileresponse.py:345:36: error: If condition is always true  [redundant-expr]
+ aiohttp/web_fileresponse.py:345:36: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-expr for more info
+ aiohttp/web_urldispatcher.py:924:9: error: Returning Any from function declared to return "StreamResponse"  [no-any-return]
+ aiohttp/web_urldispatcher.py:924:9: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-no-any-return for more info

colour (https://github.com/colour-science/colour)
- colour/hints/__init__.py:688: error: Argument 1 to "arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]
- colour/hints/__init__.py:690: error: Argument 1 to "arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]
- colour/hints/__init__.py:699: error: Argument 1 to "number_or_arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]
- colour/hints/__init__.py:701: error: Argument 1 to "number_or_arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]
- colour/hints/__init__.py:710: error: Argument 1 to "arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]
- colour/hints/__init__.py:712: error: Argument 1 to "arraylike" has incompatible type "list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | str | _NestedSequence[complex | bytes | str]]"; expected "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"  [arg-type]

mypy (https://github.com/python/mypy)
+ mypy/plugins/attrs.py:771: error: Redundant call to get_proper_type()  [misc]

starlette (https://github.com/encode/starlette)
+ starlette/requests.py:202: error: Returning Any from function declared to return "URL"  [no-any-return]

zulip (https://github.com/zulip/zulip)
+ zproject/configured_settings.py:25: error: Cannot determine type of "LDAP_APPEND_DOMAIN"  [has-type]
+ zproject/configured_settings.py:25: error: Cannot determine type of "AUTH_LDAP_USER_SEARCH"  [has-type]
+ zproject/configured_settings.py:25: error: Cannot determine type of "AUTH_LDAP_REVERSE_EMAIL_SEARCH"  [has-type]
+ zproject/configured_settings.py:25: error: Cannot determine type of "AUTH_LDAP_USER_ATTR_MAP"  [has-type]
- zerver/lib/logging_util.py:257: error: "AbstractBaseUser" has no attribute "delivery_email"  [attr-defined]
- zerver/lib/logging_util.py:257: error: "AbstractBaseUser" has no attribute "realm"  [attr-defined]
+ zproject/computed_settings.py:166: error: Need type annotation for "service"  [var-annotated]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/specs/openapi/adapter/parameters.py:1020: error: Subclass of "dict[str, Any]" and "bool" cannot exist: have distinct disjoint bases  [unreachable]
+ src/schemathesis/specs/openapi/adapter/parameters.py:1021: error: Statement is unreachable  [unreachable]
+ src/schemathesis/pytest/lazy.py: note: In function "parametrize":
+ src/schemathesis/pytest/lazy.py:208: error: Statement is unreachable  [unreachable]

core (https://github.com/home-assistant/core)
+ homeassistant/util/variance.py:41: error: Right operand of "and" is never evaluated  [unreachable]
+ homeassistant/util/variance.py:42: error: Statement is unreachable  [unreachable]
+ homeassistant/setup.py:448: error: Statement is unreachable  [unreachable]
+ homeassistant/components/device_tracker/config_entry.py:56: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/intent/timers.py:496: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/cloud/google_config.py:293: error: Returning Any from function declared to return "bool"  [no-any-return]
+ homeassistant/components/airvisual_pro/__init__.py:97: error: Statement is unreachable  [unreachable]
+ homeassistant/components/imap/__init__.py:254: error: Item "str" of "Message[str, str] | Any | str" has no attribute "get_payload"  [union-attr]
+ homeassistant/components/imap/__init__.py:264: error: Incompatible return value type (got "Message[str, str] | Any | str", expected "Message[str, str]")  [return-value]
+ homeassistant/components/homekit/type_cameras.py:306: error: Returning Any from function declared to return "str | None"  [no-any-return]
+ homeassistant/components/asuswrt/sensor.py:295: error: Returning Any from function declared to return "float | int | str | None"  [no-any-return]

pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/config/__init__.py:1199: error: Returning Any from function declared to return "TerminalWriter"  [no-any-return]
+ src/_pytest/nodes.py:506: error: Returning Any from function declared to return "tuple[str | Path, int | None]"  [no-any-return]
+ src/_pytest/python.py:742: error: Returning Any from function declared to return "object | None"  [no-any-return]
+ testing/test_reports.py:308: error: Incompatible types in assignment (expression has type "CollectReport", variable has type "TestReport")  [assignment]
+ testing/test_python_path.py:128: error: Statement is unreachable  [unreachable]
+ testing/test_compat.py:149: error: Statement is unreachable  [unreachable]
+ testing/test_compat.py:150: error: Unused "type: ignore" comment  [unused-ignore]
+ testing/test_compat.py:154: error: Statement is unreachable  [unreachable]
+ testing/test_compat.py:184: error: Statement is unreachable  [unreachable]
+ testing/test_compat.py:185: error: Unused "type: ignore" comment  [unused-ignore]
+ testing/test_compat.py:189: error: Statement is unreachable  [unreachable]

rich (https://github.com/Textualize/rich)
+ rich/_fileno.py:18: error: Returning Any from function declared to return "int | None"  [no-any-return]
+ rich/measure.py:115: error: Returning Any from function declared to return "Measurement"  [no-any-return]

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/generic.py:3584: error: Argument 1 to "__call__" of "EngFormatter" has incompatible type "float | complex"; expected "float"  [arg-type]

discord.py (https://github.com/Rapptz/discord.py)
- discord/scheduled_event.py:490: error: Incompatible types in assignment (expression has type "str | None", target has type "str")  [assignment]
- discord/appinfo.py:412: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:415: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:418: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:420: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:462: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:464: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:466: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:482: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:484: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/appinfo.py:486: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/invite.py:470: error: Item "Object" of "Guild | Object" has no attribute "get_channel"  [union-attr]
- discord/webhook/async_.py:581: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:585: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:587: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:591: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:593: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:597: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:606: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:609: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:613: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:615: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:617: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:634: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]
- discord/webhook/async_.py:637: error: Unsupported target for indexed assignment ("dict[str, Any] | None")  [index]

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/internal/coverage/instrumentation_py3_12.py:230: error: Incompatible types in assignment (expression has type "tuple[str | None, tuple[str, ...]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
+ ddtrace/internal/coverage/instrumentation_py3_12.py:230: error: Incompatible types in assignment (expression has type "tuple[None, tuple[str, ...]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
- ddtrace/internal/coverage/instrumentation_py3_12.py:232: error: List item 0 has incompatible type "str | None"; expected "str"  [list-item]
+ ddtrace/internal/coverage/instrumentation_py3_12.py:232: error: List item 0 has incompatible type "None"; expected "str"  [list-item]
- ddtrace/internal/coverage/instrumentation_py3_12.py:235: error: Incompatible types in assignment (expression has type "tuple[str | None, tuple[str | None]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
+ ddtrace/internal/coverage/instrumentation_py3_12.py:235: error: Incompatible types in assignment (expression has type "tuple[None, tuple[None]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
- ddtrace/internal/coverage/instrumentation_py3_12.py:243: error: Incompatible types in assignment (expression has type "tuple[str | None, tuple[str, ...]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
+ ddtrace/internal/coverage/instrumentation_py3_12.py:243: error: Incompatible types in assignment (expression has type "tuple[None, tuple[str, ...]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
- ddtrace/internal/coverage/instrumentation_py3_12.py:248: error: Incompatible types in assignment (expression has type "tuple[str | None, tuple[str]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]
+ ddtrace/internal/coverage/instrumentation_py3_12.py:248: error: Incompatible types in assignment (expression has type "tuple[None, tuple[str]]", target has type "tuple[str, tuple[str, ...]]")  [assignment]

trio (https://github.com/python-trio/trio)
+ src/trio/testing/_fake_net.py:89: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2454: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2457: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2523: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2524: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2525: error: Unused "type: ignore" comment  [unused-ignore]
+ src/trio/_core/_tests/test_run.py:2556: error: Unused "type: ignore" comment  [unused-ignore]

jax (https://github.com/google/jax)
+ jax/_src/export/shape_poly.py:2146: error: Unused "type: ignore" comment  [unused-ignore]
+ jax/_src/numpy/indexing.py:342: error: Unused "type: ignore[assignment]" comment  [unused-ignore]

pylint (https://github.com/pycqa/pylint)
+ pylint/checkers/utils.py:1343: error: Returning Any from function declared to return "str | None"  [no-any-return]
+ pylint/checkers/classes/class_checker.py:256: error: Call to untyped function (unknown) in typed context  [no-untyped-call]

dulwich (https://github.com/dulwich/dulwich)
+ dulwich/pack.py:4403: error: Argument 1 to "append" of "list" has incompatible type "tuple[int | None, int, list[bytes] | bytes]"; expected "tuple[int, int, list[bytes] | bytes]"  [arg-type]

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/test.py:1285: error: Cannot determine type of "headers"  [has-type]

pyodide (https://github.com/pyodide/pyodide)
+ src/py/pyodide/code.py:45: error: Unused "type: ignore" comment  [unused-ignore]

bidict (https://github.com/jab/bidict)
+ bidict/_base.py: note: In member "inverse" of class "BidictBase":
+ bidict/_base.py:189:13: error: Returning Any from function declared to return "BidictBase[VT, KT]"  [no-any-return]

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/aglib/elf.py: note: In function "get_ehdr":
+ pwndbg/aglib/elf.py:351: error: Incompatible return value type (got "tuple[int, UnionType[Elf32_Ehdr, Elf64_Ehdr]]", expected "tuple[int | None, Elf32_Ehdr | Elf64_Ehdr | None]")  [return-value]

dedupe (https://github.com/dedupeio/dedupe)
+ dedupe/training.py:319: error: Argument 1 to "len" has incompatible type "frozenset[tuple[int, int] | tuple[str, str]] | InfiniteSet"; expected "Sized"  [arg-type]
+ dedupe/training.py:328: error: Incompatible return value type (got "dict[Predicate, frozenset[int] | InfiniteSet]", expected "dict[Predicate, frozenset[int]]")  [return-value]

archinstall (https://github.com/archlinux/archinstall)
+ archinstall/tui/menu_item.py:326: error: "first_item" has type "MenuItem" which does not implement __bool__ or __len__ so it could always be true in boolean context  [truthy-bool]
+ archinstall/tui/menu_item.py:338: error: "last_item" has type "MenuItem" which does not implement __bool__ or __len__ so it could always be true in boolean context  [truthy-bool]
+ archinstall/tui/ui/menu_item.py:249: error: "first_item" has type "MenuItem" which does not implement __bool__ or __len__ so it could always be true in boolean context  [truthy-bool]
+ archinstall/tui/ui/menu_item.py:261: error: "last_item" has type "MenuItem" which does not implement __bool__ or __len__ so it could always be true in boolean context  [truthy-bool]
+ archinstall/tui/ui/components.py:1203: error: Returning Any from function declared to return "Result[ValueT]"  [no-any-return]

rotki (https://github.com/rotki/rotki)
+ rotkehlchen/tests/api/test_users.py:979: error: Statement is unreachable  [unreachable]

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/index_hierarchy.py:367: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/index_hierarchy.py:1465: error: Unused "type: ignore" comment  [unused-ignore]
+ static_frame/core/index_hierarchy.py:3408: error: Subclass of "ndarray[tuple[Any, ...], dtype[object_]]" and "dtype[Any]" cannot exist: "dtype" is final  [unreachable]
+ static_frame/core/index_hierarchy.py:3409: error: Statement is unreachable  [unreachable]
+ static_frame/core/yarn.py:321: error: Subclass of "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]" and "int" cannot exist: would have incompatible method signatures  [unreachable]
+ static_frame/core/yarn.py:321: error: Subclass of "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]" and "integer[Any]" cannot exist: would have incompatible method signatures  [unreachable]
+ static_frame/core/yarn.py:322: error: Statement is unreachable  [unreachable]
+ static_frame/core/yarn.py:476: error: Subclass of "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]" and "int" cannot exist: would have incompatible method signatures  [unreachable]
+ static_frame/core/yarn.py:476: error: Subclass of "ndarray[tuple[Any, ...], dtype[signedinteger[_64Bit]]]" and "integer[Any]" cannot exist: would have incompatible method signatures  [unreachable]
+ static_frame/core/yarn.py:478: error: Statement is unreachable  [unreachable]

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/jsonld_context.py: note: In function "process_type":
+ schema_salad/jsonld_context.py:132:34: error: Value of type "str | None" is not indexable  [index]

cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/update.py: note: In function "update":
+ cwltool/update.py:362:36: error: Function "nextupdate" could always be true in boolean context  [truthy-function]
+ cwltool/subgraph.py: note: In function "get_process":
+ cwltool/subgraph.py:271:19: error: Incompatible types in assignment (expression has type "int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None", variable has type "CommentedMap | CommentedSeq | str | None")  [assignment]

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