Skip to content

[ty] Support walrus operator scope leaking from comprehensions#23167

Open
charliermarsh wants to merge 1 commit intocharlie/reffrom
charlie/walrus
Open

[ty] Support walrus operator scope leaking from comprehensions#23167
charliermarsh wants to merge 1 commit intocharlie/reffrom
charlie/walrus

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

Closes astral-sh/ty#162.

@charliermarsh charliermarsh added bug Something isn't working ty Multi-file analysis & type inference labels Feb 9, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 9, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 9, 2026

mypy_primer results

Changes were detected when running on open source projects
mkosi (https://github.com/systemd/mkosi)
- mkosi/__init__.py:5138:80: error[unresolved-reference] Name `c` used when not defined
- mkosi/__init__.py:5143:79: error[unresolved-reference] Name `c` used when not defined
- mkosi/config.py:4661:41: error[unresolved-reference] Name `missing` used when not defined
- Found 44 diagnostics
+ Found 41 diagnostics

openlibrary (https://github.com/internetarchive/openlibrary)
- openlibrary/coverstore/code.py:532:13: warning[possibly-unresolved-reference] Name `cover` used when possibly not defined
- Found 1152 diagnostics
+ Found 1151 diagnostics

xarray (https://github.com/pydata/xarray)
- xarray/core/extension_array.py:154:16: error[unresolved-reference] Name `ea_type` used when not defined
+ xarray/core/extension_array.py:154:16: warning[possibly-unresolved-reference] Name `ea_type` used when possibly not defined

sympy (https://github.com/sympy/sympy)
- sympy/simplify/_cse_diff.py:152:21: warning[possibly-unresolved-reference] Name `diff_value` used when possibly not defined
- sympy/simplify/_cse_diff.py:169:46: warning[possibly-unresolved-reference] Name `diff_value` used when possibly not defined
- Found 16320 diagnostics
+ Found 16318 diagnostics

scikit-learn (https://github.com/scikit-learn/scikit-learn)
- sklearn/tests/test_base.py:210:9: warning[possibly-unresolved-reference] Name `cls` used when possibly not defined
- Found 2516 diagnostics
+ Found 2515 diagnostics

rotki (https://github.com/rotki/rotki)
- rotkehlchen/chain/evm/decoding/curve/decoder.py:401:17: warning[possibly-unresolved-reference] Name `withdrawn_asset` used when possibly not defined
- Found 2108 diagnostics
+ Found 2107 diagnostics

core (https://github.com/home-assistant/core)
- homeassistant/components/bthome/event.py:115:27: warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/bthome/event.py:115:51: warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/habitica/util.py:124:17: warning[possibly-unresolved-reference] Name `stats` used when possibly not defined
- homeassistant/components/habitica/util.py:131:17: warning[possibly-unresolved-reference] Name `stats` used when possibly not defined
- homeassistant/components/igloohome/lock.py:39:27: warning[possibly-unresolved-reference] Name `bridge` used when possibly not defined
- homeassistant/components/ista_ecotrend/sensor.py:273:47: error[unresolved-reference] Name `statistics_sum` used when not defined
- homeassistant/components/mqtt/siren.py:343:28: warning[possibly-unresolved-reference] Name `data_attr` used when possibly not defined
- homeassistant/components/notion/binary_sensor.py:122:17: warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/binary_sensor.py:123:17: warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/sensor.py:57:17: warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/sensor.py:58:17: warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/recorder/history/__init__.py:911:53: error[unresolved-reference] Name `prev_state` used when not defined
- homeassistant/components/recorder/history/__init__.py:927:49: error[unresolved-reference] Name `prev_state` used when not defined
- homeassistant/components/shelly/config_flow.py:643:13: warning[possibly-unresolved-reference] Name `mac` used when possibly not defined
- homeassistant/components/tplink/entity.py:434:29: warning[possibly-unresolved-reference] Name `desc` used when possibly not defined
- homeassistant/components/xiaomi_ble/event.py:194:27: warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/xiaomi_ble/event.py:194:51: warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/xiaomi_miio/sensor.py:883:19: warning[possibly-unresolved-reference] Name `value` used when possibly not defined
- homeassistant/helpers/integration_platform.py:137:9: warning[possibly-unresolved-reference] Name `future` used when possibly not defined
- homeassistant/helpers/translation.py:82:20: warning[possibly-unresolved-reference] Name `category_strings` used when possibly not defined
- Found 12021 diagnostics
+ Found 12001 diagnostics

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 9, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
possibly-unresolved-reference 1 21 0
unresolved-reference 0 7 0
Total 1 28 0
Raw diff (29 changes)
core (https://github.com/home-assistant/core)
- homeassistant/components/bthome/event.py:115:27 warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/bthome/event.py:115:51 warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/ista_ecotrend/sensor.py:273:47 error[unresolved-reference] Name `statistics_sum` used when not defined
- homeassistant/components/xiaomi_ble/event.py:194:27 warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/components/xiaomi_ble/event.py:194:51 warning[possibly-unresolved-reference] Name `address_event_class` used when possibly not defined
- homeassistant/helpers/integration_platform.py:137:9 warning[possibly-unresolved-reference] Name `future` used when possibly not defined
- homeassistant/components/habitica/util.py:124:17 warning[possibly-unresolved-reference] Name `stats` used when possibly not defined
- homeassistant/components/habitica/util.py:131:17 warning[possibly-unresolved-reference] Name `stats` used when possibly not defined
- homeassistant/components/igloohome/lock.py:39:27 warning[possibly-unresolved-reference] Name `bridge` used when possibly not defined
- homeassistant/components/mqtt/siren.py:343:28 warning[possibly-unresolved-reference] Name `data_attr` used when possibly not defined
- homeassistant/components/notion/binary_sensor.py:120:17 warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/binary_sensor.py:121:17 warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/sensor.py:56:17 warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/notion/sensor.py:57:17 warning[possibly-unresolved-reference] Name `sensor` used when possibly not defined
- homeassistant/components/recorder/history/__init__.py:911:53 error[unresolved-reference] Name `prev_state` used when not defined
- homeassistant/components/recorder/history/__init__.py:927:49 error[unresolved-reference] Name `prev_state` used when not defined
- homeassistant/components/shelly/config_flow.py:643:13 warning[possibly-unresolved-reference] Name `mac` used when possibly not defined
- homeassistant/components/tplink/entity.py:434:29 warning[possibly-unresolved-reference] Name `desc` used when possibly not defined
- homeassistant/components/xiaomi_miio/sensor.py:883:19 warning[possibly-unresolved-reference] Name `value` used when possibly not defined
- homeassistant/helpers/translation.py:82:20 warning[possibly-unresolved-reference] Name `category_strings` used when possibly not defined

mkosi (https://github.com/systemd/mkosi)
- mkosi/__init__.py:5146:80 error[unresolved-reference] Name `c` used when not defined
- mkosi/__init__.py:5151:79 error[unresolved-reference] Name `c` used when not defined
- mkosi/config.py:4757:41 error[unresolved-reference] Name `missing` used when not defined

openlibrary (https://github.com/internetarchive/openlibrary)
- openlibrary/coverstore/code.py:533:13 warning[possibly-unresolved-reference] Name `cover` used when possibly not defined

rotki (https://github.com/rotki/rotki)
- rotkehlchen/chain/evm/decoding/curve/decoder.py:401:17 warning[possibly-unresolved-reference] Name `withdrawn_asset` used when possibly not defined

sympy (https://github.com/sympy/sympy)
- sympy/simplify/_cse_diff.py:152:21 warning[possibly-unresolved-reference] Name `diff_value` used when possibly not defined
- sympy/simplify/_cse_diff.py:169:46 warning[possibly-unresolved-reference] Name `diff_value` used when possibly not defined

xarray (https://github.com/pydata/xarray)
- xarray/core/extension_array.py:154:16 error[unresolved-reference] Name `ea_type` used when not defined
+ xarray/core/extension_array.py:154:16 warning[possibly-unresolved-reference] Name `ea_type` used when possibly not defined

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review February 9, 2026 02:50
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 9, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing charlie/walrus (1ba1351) with charlie/ref (9259e3d)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh marked this pull request as draft February 9, 2026 03:47
@charliermarsh charliermarsh marked this pull request as ready for review February 9, 2026 14:44
@AlexWaygood AlexWaygood removed their request for review February 10, 2026 15:50
@carljm carljm assigned carljm and unassigned carljm Feb 14, 2026
@charliermarsh charliermarsh marked this pull request as draft February 18, 2026 16:42
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Feb 18, 2026

Memory usage report

Memory usage unchanged ✅

@charliermarsh charliermarsh changed the base branch from main to charlie/ref February 18, 2026 17:05
@charliermarsh charliermarsh marked this pull request as ready for review February 18, 2026 17:05
@charliermarsh charliermarsh marked this pull request as draft February 18, 2026 17:14
@charliermarsh charliermarsh marked this pull request as ready for review February 18, 2026 17:16
@charliermarsh
Copy link
Copy Markdown
Member Author

I pulled some of the enabling refactors into #23394 to make this PR smaller / more focused on walrus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

walrus expressions in a comprehension scope "leak" into the comprehension's enclosing scope

2 participants