Skip to content

[basedpyright parity] Warn about provably invalid casts#4277

Open
fangyi-zhou wants to merge 1 commit into
facebook:mainfrom
fangyi-zhou:invalid-cast-warning
Open

[basedpyright parity] Warn about provably invalid casts#4277
fangyi-zhou wants to merge 1 commit into
facebook:mainfrom
fangyi-zhou:invalid-cast-warning

Conversation

@fangyi-zhou

@fangyi-zhou fangyi-zhou commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3725

Casts between runtime-disjoint types often hide incorrect assumptions, but uncertain overlap should not produce noise.

Add an opt-in invalid-cast diagnostic backed by conservative intersection checks that erase runtime-irrelevant generic arguments, honor disjoint bases and restricted type variables, and preserve plausible overlap for protocols, open classes, Never, and TypedDict/dict values.

Test Plan

New unit tests

Summary:

Casts between runtime-disjoint types often hide incorrect assumptions,
but uncertain overlap should not produce noise.

Add an opt-in invalid-cast diagnostic backed by conservative
intersection checks that erase runtime-irrelevant generic arguments,
honor disjoint bases and restricted type variables, and preserve
plausible overlap for protocols, open classes, Never, and TypedDict/dict
values.

Test Plan:

New unit tests
@github-actions

Copy link
Copy Markdown

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

pip (https://github.com/pypa/pip)
+ ERROR src/pip/_internal/resolution/resolvelib/candidates.py:45:34-83: Cast from `Literal['<Python from Requires-Python>']` to `NormalizedName` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/pip/_vendor/packaging/licenses/__init__.py:183:16-186:6: Cast from `LiteralString` to `NormalizedLicenseExpression` is invalid because the types are disjoint [invalid-cast]

openlibrary (https://github.com/internetarchive/openlibrary)
+ ERROR openlibrary/core/lending.py:68:41-52: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR openlibrary/solr/update.py:36:21-41: Cast from `None` to `DataProvider` is invalid because the types are disjoint [invalid-cast]

packaging (https://github.com/pypa/packaging)
+ ERROR src/packaging/licenses/__init__.py:195:16-198:6: Cast from `LiteralString` to `NormalizedLicenseExpression` is invalid because the types are disjoint [invalid-cast]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ ERROR mitmproxy/dns.py:206:56-76: Cast from `str` to `dict[int | str, int | str]` is invalid because the types are disjoint [invalid-cast]

steam.py (https://github.com/Gobot1234/steam.py)
+ ERROR steam/enums.py:1516:33-1518:3: Cast from `dict[str, str]` to `Mapping[str, str]` is invalid because the types are disjoint [invalid-cast]
+ ERROR steam/ext/csgo/client.py:190:20-119: Cast from `list[Item[ClientUser]]` to `BackpackItem[ClientUser]` is invalid because the types are disjoint [invalid-cast]
+ ERROR steam/utils.py:423:27-436:3: Cast from `dict[str, str]` to `Mapping[str, str]` is invalid because the types are disjoint [invalid-cast]

pytest (https://github.com/pytest-dev/pytest)
+ ERROR testing/logging/test_reporting.py:956:20-55: Cast from `test_live_logging_suspends_capture.DummyTerminal` to `TerminalReporter` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/logging/test_reporting.py:972:16-39: Cast from `TerminalReporter` to `StringIO` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/python/metafunc.py:660:17-663:14: Cast from `_IdMakerConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/python/metafunc.py:688:17-691:14: Cast from `_IdMakerConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/python/metafunc.py:705:17-708:14: Cast from `_IdMakerConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/python/metafunc.py:732:17-735:14: Cast from `_IdMakerConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/python/metafunc.py:750:17-753:14: Cast from `_IdMakerConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_assertrewrite.py:2343:46-62: Cast from `TestReprSizeVerbosity.test_get_maxsize_for_saferepr.FakeConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_junitxml.py:1030:23-45: Cast from `test_dont_configure_on_workers.FakeConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_terminal.py:1428:18-40: Cast from `test_getreportopt.FakeConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_terminal.py:2544:15-35: Cast from `test_skip_reasons_folding.X` to `CollectReport` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_terminal.py:2549:15-35: Cast from `test_skip_reasons_folding.X` to `CollectReport` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_terminal.py:2555:15-35: Cast from `test_skip_reasons_folding.X` to `CollectReport` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_tmpdir.py:63:22-52: Cast from `FakeConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR testing/test_tmpdir.py:78:22-51: Cast from `FakeConfig` to `Config` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/_pytest/raises.py:1142:37-61: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/_pytest/raises.py:1167:37-61: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/_pytest/raises.py:1197:21-45: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]

jax (https://github.com/google/jax)
+ ERROR jax/experimental/mosaic/gpu/constraints.py:1003:28-46: Cast from `None` to `AlwaysTrue | Divides | Equals | IsSupportedBroadcast | IsTransferable | IsValidMmaTiling | MinorDimDivisibleBy | NotOfType | OneOf | Relayout` is invalid because the types are disjoint [invalid-cast]
+ ERROR jax/experimental/mosaic/gpu/fragmented_array.py:2023:20-47: Cast from `list[Unknown]` to `tuple[int, ...]` is invalid because the types are disjoint [invalid-cast]
+ ERROR jax/experimental/mosaic/gpu/fragmented_array.py:2064:20-47: Cast from `list[Unknown]` to `tuple[int, ...]` is invalid because the types are disjoint [invalid-cast]

spark (https://github.com/apache/spark)
+ ERROR python/pyspark/pandas/frame.py:6832:25-6835:10: Cast from `datetime` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/pandas/frame.py:6905:23-6908:10: Cast from `datetime` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/sql/connect/plan.py:1148:56-70: Cast from `list[str] | list[Unknown]` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/sql/connect/readwriter.py:629:45-62: Cast from `tuple[list[str] | str, ...]` to `list[str]` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/sql/connect/readwriter.py:745:43-60: Cast from `tuple[list[str] | str, ...]` to `list[str]` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/sql/connect/streaming/readwriter.py:519:64-81: Cast from `tuple[str, ...]` to `list[str]` is invalid because the types are disjoint [invalid-cast]
+ ERROR python/pyspark/sql/connect/streaming/readwriter.py:536:62-79: Cast from `tuple[str, ...]` to `list[str]` is invalid because the types are disjoint [invalid-cast]

cwltool (https://github.com/common-workflow-language/cwltool)
+ ERROR cwltool/builder.py:363:30-50: Cast from `MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None] | list[MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]]` to `CWLFileType` is invalid because the types are disjoint [invalid-cast]
+ ERROR cwltool/builder.py:473:45-85: Cast from `MutableMapping[Unknown, Unknown]` to `CWLDirectoryType | CWLFileType` is invalid because the types are disjoint [invalid-cast]
+ ERROR cwltool/builder.py:558:30-55: Cast from `MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None] | list[MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]]` to `CWLDirectoryType` is invalid because the types are disjoint [invalid-cast]
+ ERROR cwltool/command_line_tool.py:1519:58-89: Cast from `CWLDirectoryType | CWLFileType` to `MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]` is invalid because the types are disjoint [invalid-cast]
+ ERROR cwltool/cwlprov/ro.py:361:55-363:22: Cast from `Aggregate` to `dict[str, Any] | None` is invalid because the types are disjoint [invalid-cast]
+ ERROR cwltool/job.py:135:36-64: Cast from `None` to `((str, int) -> MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]) | partial[MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]]` is invalid because the types are disjoint [invalid-cast]
+ ERROR tests/test_path_checks.py:173:25-94: Cast from `dict[str, str | dict[str, str]]` to `MutableMapping[str, MutableMapping[str, CWLOutputType | None] | MutableSequence[CWLOutputType | None] | bool | float | int | str | CWLDirectoryType | CWLFileType | None]` is invalid because the types are disjoint [invalid-cast]

cryptography (https://github.com/pyca/cryptography)
+ ERROR tests/x509/test_x509_ext.py:2425:32-61: Cast from `Literal['invalid']` to `GeneralName` is invalid because the types are disjoint [invalid-cast]
+ ERROR tests/x509/test_x509_ext.py:2489:32-61: Cast from `Literal['invalid']` to `GeneralName` is invalid because the types are disjoint [invalid-cast]
+ ERROR tests/x509/test_x509_ext.py:2614:32-61: Cast from `Literal['invalid']` to `GeneralName` is invalid because the types are disjoint [invalid-cast]

setuptools (https://github.com/pypa/setuptools)
+ ERROR setuptools/_vendor/packaging/licenses/__init__.py:144:16-147:6: Cast from `LiteralString` to `NormalizedLicenseExpression` is invalid because the types are disjoint [invalid-cast]

pwndbg (https://github.com/pwndbg/pwndbg)
+ ERROR pwndbg/aglib/__init__.py:30:36-62: Cast from `None` to `PwndbgArchitecture` is invalid because the types are disjoint [invalid-cast]
+ ERROR pwndbg/aglib/__init__.py:31:33-56: Cast from `None` to `RegisterManager` is invalid because the types are disjoint [invalid-cast]

operator (https://github.com/canonical/operator)
+ ERROR ops/_private/harness.py:689:20-42: Cast from `dict[str, Any] | dict[Unknown, Unknown]` to `_RawConfig` is invalid because the types are disjoint [invalid-cast]

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ ERROR pymongo/auth_shared.py:237:20-69: Cast from `list[bytes]` to `tuple[bytes, bytes]` is invalid because the types are disjoint [invalid-cast]

schemathesis (https://github.com/schemathesis/schemathesis)
+ ERROR src/schemathesis/specs/openapi/operations.py:61:54-69:10: `None` is not assignable to upper bound `ResponsesContainer[Unknown]` of type variable `R` [bad-specialization]
+ ERROR src/schemathesis/specs/openapi/operations.py:62:24-48: Cast from `Literal['']` to `Literal['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'query', 'trace']` is invalid because the types are disjoint [invalid-cast]

pandera (https://github.com/pandera-dev/pandera)
+ ERROR pandera/api/base/model_components.py:77:34-45: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]

aiohttp (https://github.com/aio-libs/aiohttp)
+ ERROR aiohttp/connector.py:675:31-677:14: Cast from `_TransportPlaceholder` to `ResponseHandler` is invalid because the types are disjoint [invalid-cast]

strawberry (https://github.com/strawberry-graphql/strawberry)
+ ERROR strawberry/relay/fields.py:175:29-68: Cast from `None` to `Node` is invalid because the types are disjoint [invalid-cast]

zulip (https://github.com/zulip/zulip)
+ ERROR corporate/tests/test_stripe.py:6206:37-65: Cast from `Literal[0]` to `BillingSessionEventType` is invalid because the types are disjoint [invalid-cast]
+ ERROR corporate/tests/test_stripe.py:6308:37-65: Cast from `Literal[0]` to `BillingSessionEventType` is invalid because the types are disjoint [invalid-cast]

dragonchain (https://github.com/dragonchain/dragonchain)
+ ERROR dragonchain/job_processor/contract_job.py:99:30-77: Cast from `None` to `SmartContractModel` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/job_processor/contract_job.py:104:37-84: Cast from `None` to `SmartContractModel` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/job_processor/contract_job.py:111:37-84: Cast from `None` to `SmartContractModel` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/lib/database/redis.py:35:20-39: Cast from `None` to `Redis[Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/lib/database/redis.py:36:24-43: Cast from `None` to `Redis[Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/lib/database/redisearch.py:394:29-55: Cast from `None` to `BlockModel` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/lib/queue.py:154:16-95: Cast from `str | None` to `bytes` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/lib/queue.py:253:30-109: Cast from `str | None` to `bytes` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/transaction_processor/level_5_actions.py:52:26-37: Cast from `None` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/transaction_processor/level_5_actions.py:53:26-37: Cast from `None` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/transaction_processor/level_5_actions.py:54:14-26: Cast from `None` to `bool` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/transaction_processor/level_5_actions.py:55:26-57: Cast from `None` to `InterchainModel` is invalid because the types are disjoint [invalid-cast]
+ ERROR dragonchain/webserver/lib/dragonnet.py:53:23-49: Cast from `None` to `BlockModel` is invalid because the types are disjoint [invalid-cast]

pandas (https://github.com/pandas-dev/pandas)
+ ERROR pandas/core/indexes/multi.py:605:26-60: Cast from `zip_longest[tuple[Hashable, ...]]` to `list[Sequence[Hashable]]` is invalid because the types are disjoint [invalid-cast]

hydpy (https://github.com/hydpy-dev/hydpy)
+ ERROR hydpy/core/sequencetools.py:1679:24-76: Cast from `OptionContextStr[SeriesFileType]` to `Literal['asc', 'nc', 'npy']` is invalid because the types are disjoint [invalid-cast]
+ ERROR hydpy/core/sequencetools.py:1730:24-86: Cast from `OptionContextStr[SeriesAggregationType]` to `Literal['mean', 'none']` is invalid because the types are disjoint [invalid-cast]
+ ERROR hydpy/exe/xmltools.py:2344:24-35: Cast from `Literal['?']` to `Name` is invalid because the types are disjoint [invalid-cast]

dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ERROR ddtrace/debugging/_function/discovery.py:140:24-59: Cast from `FunctionType` to `FullyNamedFunction` is invalid because the types are disjoint [invalid-cast]
+ ERROR ddtrace/debugging/_function/discovery.py:289:76-100: Cast from `FullyNamedFunction` to `FunctionType` is invalid because the types are disjoint [invalid-cast]
+ ERROR ddtrace/debugging/_function/discovery.py:294:76-100: Cast from `FullyNamedFunction` to `FunctionType` is invalid because the types are disjoint [invalid-cast]
+ ERROR ddtrace/debugging/_function/discovery.py:355:24-47: Cast from `FunctionType` to `FullyNamedFunction` is invalid because the types are disjoint [invalid-cast]
+ ERROR ddtrace/internal/utils/inspection.py:75:21-33: Cast from `FunctionType` to `partial[Unknown]` is invalid because the types are disjoint [invalid-cast]

xarray-dataclasses (https://github.com/astropenguin/xarray-dataclasses)
+ ERROR xarray_dataclasses/datamodel.py:104:22-34: Cast from `None` to `tuple[str, ...]` is invalid because the types are disjoint [invalid-cast]

meson (https://github.com/mesonbuild/meson)
+ ERROR mesonbuild/interpreter/decorators.py:44:49-75: Cast from `dict[str, HoldableObject | MesonInterpreterObject | Sequence[TYPE_elementary] | Sequence[TYPE_var] | bool | dict[str, TYPE_elementary] | dict[str, TYPE_var] | int | str] | None` to `MachineMapArgs` is invalid because the types are disjoint [invalid-cast]
+ ERROR mesonbuild/modules/java.py:65:25-63: Cast from `str | None` to `list[str]` is invalid because the types are disjoint [invalid-cast]
+ ERROR mesonbuild/utils/core.py:174:33-51: Cast from `Literal['']` to `SubProject` is invalid because the types are disjoint [invalid-cast]

werkzeug (https://github.com/pallets/werkzeug)
+ ERROR src/werkzeug/middleware/lint.py:438:29-63: Cast from `list[Any]` to `tuple[int, Headers]` is invalid because the types are disjoint [invalid-cast]

core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/accuweather/sensor.py:72:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:79:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:95:35-48: Cast from `dict[str, Any]` to `float` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:100:35-46: Cast from `dict[str, Any]` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:105:35-46: Cast from `dict[str, Any]` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:177:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:183:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:265:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:300:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/accuweather/sensor.py:343:35-46: Cast from `dict[str, Any]` to `int` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/aws_s3/__init__.py:31:16-34: Cast from `MappingProxyType[str, Any]` to `dict[Unknown, Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/cloudflare_r2/__init__.py:37:16-34: Cast from `MappingProxyType[str, Any]` to `dict[Unknown, Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/google_travel_time/services.py:118:20-83: Cast from `dict[str, list[dict[Unknown, Unknown]]]` to `dict[str, bool | dict[str, JsonValueType] | float | int | list[JsonValueType] | str | None] | None` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/google_travel_time/services.py:151:20-83: Cast from `dict[str, list[dict[Unknown, Unknown]]]` to `dict[str, bool | dict[str, JsonValueType] | float | int | list[JsonValueType] | str | None] | None` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/knx/knx_module.py:106:24-62: Cast from `MappingProxyType[str, Any]` to `KNXConfigEntryOptions` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/miele/sensor.py:1266:23-44: Cast from `float | int` to `str` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/miele/switch.py:213:44-56: Cast from `dict[str, bool | int | str]` to `bool` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/miele/switch.py:214:49-61: Cast from `dict[str, bool | int | str]` to `bool` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/mqtt/entity.py:374:33-66: Cast from `MappingProxyType[str, Any]` to `MqttSubentryData` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/components/stookwijzer/services.py:46:20-53:10: Cast from `dict[str, list[Forecast]]` to `dict[str, bool | dict[str, JsonValueType] | float | int | list[JsonValueType] | str | None] | None` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/data_entry_flow.py:303:27-46: Cast from `dict[@_, @_]` to `_FlowContextT` is invalid because the types are disjoint [invalid-cast]
+ ERROR homeassistant/loader.py:682:32-81: Cast from `bool | dict[str, JsonValueType] | float | int | list[JsonValueType] | str | None` to `Manifest` is invalid because the types are disjoint [invalid-cast]

trio (https://github.com/python-trio/trio)
+ ERROR src/trio/_core/_run.py:2663:21-2666:6: Cast from `None` to `list[tuple[int, int]]` is invalid because the types are disjoint [invalid-cast]

paasta (https://github.com/yelp/paasta)
+ ERROR paasta_tools/long_running_service_tools.py:407:21-421:18: Cast from `dict[@_, @_] | dict[Unknown, Unknown]` to `MetricsProviderDict` is invalid because the types are disjoint [invalid-cast]

xarray (https://github.com/pydata/xarray)
+ ERROR xarray/tests/test_dataarray.py:6252:24-64: Cast from `dict[Hashable, DataArray]` to `DataArray` is invalid because the types are disjoint [invalid-cast]
+ ERROR xarray/tests/test_dataarray.py:6324:24-64: Cast from `dict[Hashable, DataArray]` to `DataArray` is invalid because the types are disjoint [invalid-cast]

pydantic (https://github.com/pydantic/pydantic)
+ ERROR pydantic/v1/schema.py:364:18-67: Cast from `dict_values[str, ModelField]` to `Sequence[ModelField]` is invalid because the types are disjoint [invalid-cast]
+ ERROR pydantic/v1/types.py:159:23-78: Cast from `Self@ConstrainedNumberMeta` to `ConstrainedInt` is invalid because the types are disjoint [invalid-cast]

graphql-core (https://github.com/graphql-python/graphql-core)
+ ERROR tests/execution/incremental/test_incremental_executor.py:128:48-62: Cast from `None` to `Path` is invalid because the types are disjoint [invalid-cast]
+ ERROR tests/execution/incremental/test_incremental_executor.py:201:17-31: Cast from `None` to `Path` is invalid because the types are disjoint [invalid-cast]
+ ERROR tests/execution/incremental/test_incremental_executor.py:230:17-31: Cast from `None` to `Path` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/utilities/build_client_schema.py:286:34-84: Cast from `dict[str, Any]` to `IntrospectionEnumType | IntrospectionInputObjectType | IntrospectionInterfaceType | IntrospectionObjectType | IntrospectionScalarType | IntrospectionUnionType` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/utilities/build_client_schema.py:321:34-87: Cast from `dict[str, Any]` to `IntrospectionEnumType | IntrospectionInputObjectType | IntrospectionInterfaceType | IntrospectionObjectType | IntrospectionScalarType | IntrospectionUnionType` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/utilities/build_client_schema.py:358:34-360:10: Cast from `dict[str, Any]` to `IntrospectionEnumType | IntrospectionInputObjectType | IntrospectionInterfaceType | IntrospectionObjectType | IntrospectionScalarType | IntrospectionUnionType` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/validation/rules/known_argument_names.py:39:30-58: Cast from `tuple[GraphQLDirective, ...]` to `list[Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/validation/rules/known_directives.py:38:50-80: Cast from `tuple[GraphQLDirective, ...]` to `list[Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/validation/rules/provided_required_arguments.py:55:30-58: Cast from `tuple[GraphQLDirective, ...]` to `list[Unknown]` is invalid because the types are disjoint [invalid-cast]
+ ERROR src/graphql/validation/rules/unique_directives_per_location.py:42:50-80: Cast from `tuple[GraphQLDirective, ...]` to `list[Unknown]` is invalid because the types are disjoint [invalid-cast]

django-modern-rest (https://github.com/wemake-services/django-modern-rest)
+ ERROR dmr/validation/settings.py:83:20-48: Cast from `Mapping[str, Any]` to `_SettingsModel` is invalid because the types are disjoint [invalid-cast]

@fangyi-zhou
fangyi-zhou marked this pull request as ready for review July 24, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new rule - invalid cast

1 participant