Fix attribute writes after impossible narrowing - #4512
Open
cakeni wants to merge 2 commits into
Open
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D115588096. (Because this pull request was imported automatically, there will not be any future comments.) |
This comment has been minimized.
This comment has been minimized.
Contributor
|
Thanks for the PR! Could you review the |
shobhitmehro
self-requested a review
August 12, 2026 22:23
|
Diff from mypy_primer, showing the effect of this PR on open source code: ============================================================
SUMMARY
============================================================
Total: +12 new errors, -46 fixed errors
Projects with changes (21):
cloud-init: +1 -3
dulwich: +0 -3
steam.py: +0 -1
bokeh: +0 -1
spark: +0 -1
prefect: +0 -1
colour: +2 -1
freqtrade: +0 -2
setuptools: +0 -6
apprise: +0 -1
manticore: +0 -2
beartype: +0 -1
pandera: +0 -1
ibis: +6 -6
hydpy: +0 -1
meson: +0 -5
werkzeug: +0 -1
core: +1 -1
paasta: +0 -2
sphinx: +1 -5
poetry: +1 -1
============================================================
FULL DIFF DETAILS
------------------------------------------------------------
cloud-init (https://github.com/canonical/cloud-init)
- ERROR cloudinit/sources/DataSourceHetzner.py:204:36-49: `Literal['_unset']` is not assignable to attribute `_network_config` with type `Never` [bad-assignment]
- ERROR cloudinit/sources/DataSourceScaleway.py:320:36-49: `Literal['_unset']` is not assignable to attribute `_network_config` with type `Never` [bad-assignment]
- ERROR cloudinit/sources/DataSourceSmartOS.py:205:34-38: `None` is not assignable to attribute `md_client` with type `Never` [bad-assignment]
+ ERROR cloudinit/sources/DataSourceSmartOS.py:205:34-38: `None` is not assignable to attribute `md_client` with type `str` [bad-assignment]
dulwich (https://github.com/dulwich/dulwich)
- ERROR dulwich/repo.py:1677:42-1679:22: `ObjectFormat` is not assignable to attribute `object_format` with type `Never` [bad-assignment]
- ERROR dulwich/repo.py:1681:42-63: `ObjectFormat` is not assignable to attribute `object_format` with type `Never` [bad-assignment]
- ERROR dulwich/repo.py:1683:38-59: `ObjectFormat` is not assignable to attribute `object_format` with type `Never` [bad-assignment]
steam.py (https://github.com/Gobot1234/steam.py)
- ERROR steam/ext/commands/commands.py:248:49-60: `dict[str, Any]` is not assignable to attribute `__annotations__` with type `Never` [bad-assignment]
bokeh (https://github.com/bokeh/bokeh)
- ERROR src/bokeh/layouts.py:679:32-43: `Literal['fixed', 'inherit', 'scale_both', 'scale_height', 'scale_width', 'stretch_both', 'stretch_height', 'stretch_width']` is not assignable to attribute `sizing_mode` with type `Never` [bad-assignment]
spark (https://github.com/apache/spark)
- ERROR python/pyspark/ml/connect/pipeline.py:78:27-33: `list[Unknown]` is not assignable to attribute `stages` with type `Never` [bad-assignment]
prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/integrations/prefect-gcp/prefect_gcp/workers/cloud_run_v2.py:302:30-38: `str` is not assignable to attribute `_job_name` with type `Never` [bad-assignment]
colour (https://github.com/colour-science/colour)
- ERROR colour/io/fichet2021.py:843:36-845:10: `list[Image_Specification_Attribute]` is not assignable to attribute `attributes` with type `Never` [bad-assignment]
+ ERROR colour/io/fichet2021.py:843:36-845:10: `list[Image_Specification_Attribute]` is not assignable to attribute `attributes` with type `tuple[Unknown, ...]` [bad-assignment]
+ ERROR colour/io/fichet2021.py:848:13-44: Object of class `tuple` has no attribute `extend` [missing-attribute]
freqtrade (https://github.com/freqtrade/freqtrade)
- ERROR freqtrade/freqtradebot.py:1933:46-94: `str` is not assignable to attribute `ft_cancel_reason` with type `Never` [bad-assignment]
- ERROR freqtrade/freqtradebot.py:2027:46-94: `str` is not assignable to attribute `ft_cancel_reason` with type `Never` [bad-assignment]
setuptools (https://github.com/pypa/setuptools)
- ERROR setuptools/_distutils/command/build_ext.py:198:33-69: `list[@_]` is not assignable to attribute `include_dirs` with type `Never` [bad-assignment]
- ERROR setuptools/_distutils/command/build_ext.py:219:30-32: `list[@_]` is not assignable to attribute `libraries` with type `Never` [bad-assignment]
- ERROR setuptools/_distutils/command/build_ext.py:221:33-35: `list[@_]` is not assignable to attribute `library_dirs` with type `Never` [bad-assignment]
- ERROR setuptools/_distutils/command/build_ext.py:226:26-28: `list[@_]` is not assignable to attribute `rpath` with type `Never` [bad-assignment]
- ERROR setuptools/_distutils/command/build_ext.py:293:30-32: `list[@_]` is not assignable to attribute `swig_opts` with type `Never` [bad-assignment]
- ERROR setuptools/_vendor/wheel/_bdist_wheel.py:272:30-63: `LiteralString` is not assignable to attribute `bdist_dir` with type `Never` [bad-assignment]
apprise (https://github.com/caronc/apprise)
- ERROR tests/test_config_http.py:311:26-54: `int` is not assignable to attribute `max_buffer_size` with type `Never` [bad-assignment]
manticore (https://github.com/trailofbits/manticore)
- ERROR tests/native/test_cpu_manual.py:195:18-24: `Literal[43690]` is not assignable to attribute `SI` with type `Never` [bad-assignment]
- ERROR tests/native/test_cpu_manual.py:472:18-22: `Literal[221]` is not assignable to attribute `CL` with type `Never` [bad-assignment]
beartype (https://github.com/beartype/beartype)
- ERROR beartype/_check/code/codemain.py:1469:40-1472:14: `str` is not assignable to attribute `func_curr_code` with type `Never` [bad-assignment]
pandera (https://github.com/pandera-dev/pandera)
- ERROR tests/base/test_config.py:49:35-70: `ValidationDepth | None` is not assignable to attribute `validation_depth` with type `Never` [bad-assignment]
ibis (https://github.com/ibis-project/ibis)
- ERROR ibis/common/tests/test_grounds.py:302:11-12: `Literal[3]` is not assignable to attribute `a` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:302:11-12: `Literal[3]` is not assignable to attribute `a` with type `InstanceOf` [bad-assignment]
- ERROR ibis/common/tests/test_grounds.py:701:15-16: `Literal[1]` is not assignable to attribute `a` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:701:15-16: `Literal[1]` is not assignable to attribute `a` with type `Attribute` [bad-assignment]
- ERROR ibis/common/tests/test_grounds.py:869:11-12: `Literal[2]` is not assignable to attribute `j` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:869:11-12: `Literal[2]` is not assignable to attribute `j` with type `Attribute` [bad-assignment]
- ERROR ibis/common/tests/test_grounds.py:882:11-12: `Literal[2]` is not assignable to attribute `j` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:882:11-12: `Literal[2]` is not assignable to attribute `j` with type `Attribute` [bad-assignment]
- ERROR ibis/common/tests/test_grounds.py:943:19-20: `Literal[3]` is not assignable to attribute `double_a` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:943:19-20: `Literal[3]` is not assignable to attribute `double_a` with type `Attribute` [bad-assignment]
- ERROR ibis/common/tests/test_grounds.py:1034:21-23: `Literal[11]` is not assignable to attribute `value` with type `Never` [bad-assignment]
+ ERROR ibis/common/tests/test_grounds.py:1034:21-23: `Literal[11]` is not assignable to attribute `value` with type `InstanceOf` [bad-assignment]
hydpy (https://github.com/hydpy-dev/hydpy)
- ERROR hydpy/core/importtools.py:821:35-50: `dict[str, Any]` is not assignable to attribute `_namespace` with type `Never` [bad-assignment]
meson (https://github.com/mesonbuild/meson)
- ERROR mesonbuild/build.py:2145:44-46: `list[@_]` is not assignable to attribute `extra_args` with type `Never` [bad-assignment]
- ERROR mesonbuild/build.py:2151:57-59: `list[@_]` is not assignable to attribute `extra_depends` with type `Never` [bad-assignment]
- ERROR mesonbuild/build.py:2750:27-33: `str` is not assignable to attribute `prefix` with type `Never` [bad-assignment]
- ERROR mesonbuild/build.py:2752:27-33: `str` is not assignable to attribute `suffix` with type `Never` [bad-assignment]
- ERROR mesonbuild/build.py:3620:27-76: `list[@_]` is not assignable to attribute `rename` with type `Never` [bad-assignment]
werkzeug (https://github.com/pallets/werkzeug)
- ERROR tests/test_utils.py:173:14-48: `datetime` is not assignable to attribute `date` with type `Never` [bad-assignment]
core (https://github.com/home-assistant/core)
- ERROR homeassistant/helpers/entity.py:1033:42-46: `Literal[True]` is not assignable to attribute `_no_platform_reported` with type `Never` [bad-assignment]
+ ERROR homeassistant/helpers/entity_platform.py:887:73-74: Unused `# type: ignore` comment [unused-type-ignore]
paasta (https://github.com/yelp/paasta)
- ERROR paasta_tools/paasta_service_config_loader.py:86:30-89: `list[str]` is not assignable to attribute `_clusters` with type `Never` [bad-assignment]
- ERROR paasta_tools/paasta_service_config_loader.py:146:38-148:14: `DeploymentsJsonV2` is not assignable to attribute `_deployments_json` with type `Never` [bad-assignment]
sphinx (https://github.com/sphinx-doc/sphinx)
- ERROR sphinx/directives/patches.py:54:32-44: `int` is not assignable to attribute `line` with type `Never` [bad-assignment]
- ERROR sphinx/environment/__init__.py:278:28-280:14: `_DomainsContainer` is not assignable to attribute `domains` with type `Never` [bad-assignment]
- ERROR sphinx/util/nodes.py:184:27-48: `str` is not assignable to attribute `source` with type `Never` [bad-assignment]
- ERROR sphinx/util/nodes.py:778:32-58: `str` is not assignable to attribute `source` with type `Never` [bad-assignment]
- ERROR sphinx/util/nodes.py:780:30-54: `str` is not assignable to attribute `line` with type `Never` [bad-assignment]
+ ERROR sphinx/util/nodes.py:780:30-54: `str` is not assignable to attribute `line` with type `int` [bad-assignment]
poetry (https://github.com/python-poetry/poetry)
- ERROR src/poetry/console/commands/init.py:548:26-42: `RepositoryPool` is not assignable to attribute `_pool` with type `Never` [bad-assignment]
+ ERROR src/poetry/console/commands/init.py:550:13-75: Result of call expression is of type `RepositoryPool` and is not used; assign to `_` if this is intentional [unused-call-result] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix attribute writes in impossible narrowing branches to fall back to the receiver's unnarrowed declared path when the flow receiver has become Never. Normal receiver narrowing is preserved, and the assignment continues to invalidate stale attribute facets.
The regression test verifies both sides: a Container write is accepted and an incompatible Literal[1] write is still rejected against the declared Container type.
Fixes #4478
Test Plan