Commit Graph
18617 Commits
Author SHA1 Message Date
Charlie Marsh 14f3de3e1d [ty] Handle known functions before falling back to dataclass transforms 2026-12-01 20:48:08 -05:00
Charlie Marsh d75b6a7078 [ty] Document how keyword arguments override dataclass transform defaults 2026-12-01 20:38:03 -05:00
Charlie Marsh 1362489505 [ty] Explain how we distinguish decorators from decorator factories 2026-12-01 20:37:34 -05:00
Charlie Marsh b41c8e1062 [ty] Expect positional-only self in the synthesized constructor 2026-12-01 20:32:54 -05:00
Charlie Marsh aae209818d [ty] Honor dataclass_transform on bound methods 2026-12-01 20:28:54 -05:00
Charlie Marsh 4f9f81365e [ty] Keep one live definition inline and use ThinVec for longer lists (#31168)
## Summary

As we follow control flow, we track which bindings and declarations are
live for each place. We keep up to two definitions inline to avoid
allocating for short lists. Most lists only contain one definition, but
each still needs room for two definitions or a `Vec` header.

We now keep one definition inline and use a `ThinVec` for longer lists.
Since a `ThinVec` stores its length and capacity on the heap, each list
takes up less space in `PlaceState`. Lists with exactly two definitions
now need a heap allocation.

<!-- ty-pinned-project-instructions:start -->

| Cold `ty check` | Mean change | Largest change | Projects with a lower
median |
| --- | ---: | ---: | ---: |
| Instructions | −0.06% | −0.19% (Prefect) | 27/28 |
| Peak RSS | −0.14% | −0.86% (Rich) | 23/28 |

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.

| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/30d2b7af921b8313fa2d0fc11b8a89ab5a9350db)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/275ec3fd157e9c1aae65f6920c3fcec2e523ee83)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,338,171,002.5 | 2,336,422,836.5 | -0.07% | -0.09% to -0.06% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,551,984,263 | 5,549,059,277.5 | -0.05% | -0.06% to -0.05% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 111,464,261,246 | 111,347,656,933 | -0.11% | -0.11% to -0.10% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,280,058,793 | 1,279,808,176.5 | -0.02% | -0.03% to -0.01% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,326,550,395.5 | 1,325,832,411 | -0.05% | -0.07% to -0.04% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,050,874,766 | 20,037,234,164 | -0.07% | -0.09% to -0.04% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,247,938,028.5 | 2,245,147,713 | -0.12% | -0.18% to -0.11% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,736,648,016 | 3,729,371,157.5 | -0.19% | -0.20% to -0.19% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,398,290,236 | 67,345,333,131.5 | -0.08% | -0.08% to -0.07% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,182,302,868.5 | 1,180,994,608 | -0.11% | -0.11% to -0.11% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 6,917,358,469 | 6,913,776,897 | -0.05% | -0.06% to -0.04% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,222,994,721 | 2,221,280,950.5 | -0.07% | -0.09% to -0.07% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,581,858,384 | 14,572,454,691.5 | -0.06% | -0.07% to -0.06% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,947,304,689.5 | 1,945,654,587.5 | -0.09% | -0.09% to -0.05% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,700,370,307.5 | 9,697,435,593.5 | -0.03% | -0.04% to -0.03% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,943,246,314 | 30,940,282,417 | -0.01% | -0.01% to -0.01% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,668,521,742 | 10,663,770,096.5 | -0.04% | -0.05% to -0.04% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,035,884,638.5 | 6,028,895,935.5 | -0.11% | -0.12% to -0.11% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 2,999,370,981.5 | 2,998,205,171.5 | -0.04% | -0.05% to -0.04% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,294,517,412.5 | 10,291,758,523 | -0.03% | -0.03% to -0.02% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,162,809,141 | 2,160,908,527 | -0.09% | -0.09% to -0.08% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,442,148,486.5 | 3,439,080,125 | -0.09% | -0.09% to -0.08% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
(inconclusive) | 23,720,171,802 | 23,722,082,453.5 | +0.01% | 0.00% to
+0.01% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
(inconclusive) | 10,782,027,456.5 | 10,781,334,380 | -0.01% | -0.01% to
0.00% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,077,872,092 | 6,076,872,808.5 | -0.02% | -0.02% to -0.01% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,525,432,366 | 36,514,003,754 | -0.03% | -0.03% to -0.03% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,436,073,927 | 6,429,425,478 | -0.10% | -0.11% to -0.10% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 69,166,748,493 | 69,138,608,567.5 | -0.04% | -0.04% to -0.04% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −0.48 (−0.44%) | 7/16 | +0.16 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.17 (−0.09%) | 5/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.06 (0.00%) | 7/16 | −0.67 | −0.01 (0.00%) | −0.01 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +0.14 (+0.20%) | 10/16 | +0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.15 (−0.19%) | 7/16 | −0.16 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +1.18 (+0.23%) | 9/16 | −1.00 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.68 (−0.52%) | 4/16 | −0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| +0.28 (+0.15%) | 8/16 | −0.20 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −0.37 (−0.03%) | 3/16 | −0.11 | −0.02 (0.00%) | −0.02 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| −0.25 (−0.29%) | 3/16 | +0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −0.72 (−0.32%) | 7/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.34 (−0.29%) | 4/16 | 0.00 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.11 (−0.03%) | 7/16 | +0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.88 (−0.86%) | 5/16 | 0.00 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.35 (−0.13%) | 7/16 | +0.20 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +0.19 (+0.03%) | 11/16 | +0.25 | −0.01 (0.00%) | −0.01 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| +0.22 (+0.08%) | 9/16 | −0.23 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.21 (−0.10%) | 5/16 | −0.25 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.07 (−0.06%) | 8/16 | −0.08 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.26 (−0.10%) | 6/16 | −0.11 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| −0.39 (−0.37%) | 4/16 | +0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.14 (−0.10%) | 6/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.01 (0.00%) | 8/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.20 (−0.08%) | 4/16 | −0.18 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −0.30 (−0.24%) | 4/16 | −0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −0.10 (−0.02%) | 8/16 | −0.16 | −0.01 (0.00%) | −0.01 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.35 (−0.17%) | 2/16 | −0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −1.59 (−0.11%) | 6/16 | −0.14 | −0.05 (0.00%) | −0.05 (0.00%) |

</details>

<!-- ty-pinned-project-instructions:end -->
2026-12-01 19:23:49 -05:00
Carl Meyer bb023e03a8 [ty] Bump ecosystem-analyzer to drop rclip from ecosystem runs (#31214)
## Summary

The ecosystem run on #31211 reported that ty found no Python files in
rclip on both revisions. rclip has been rewritten in Rust.

Update to [ecosystem-analyzer
#280](https://github.com/astral-sh/ecosystem-analyzer/pull/280), which
picks up [mypy-primer’s removal of
rclip](https://github.com/hauntsaninja/mypy_primer/pull/279). Update the
lockfile for `scripts/setup_primer_project.py` to the same mypy-primer
revision so local reproductions use the same project list as CI.

## Test plan

Compared the projects loaded by the analyzer with the list printed by
`setup_primer_project.py`. Both listed the same 167 projects. The script
reported rclip as unknown and still printed the ty command for cattrs.
2026-12-01 14:02:15 -08:00
Charlie Marsh 40b793b980 [ty] Skip ParamSpec bookkeeping when specializing types without signatures (#31195)
## Summary

When we specialize a type like `dict[str, list[T]]`, we set up a search
for alternative `ParamSpec` bindings at each level. Neither `dict` nor
`list` has a signature to inspect, so we initialize a set and iterate
over zero signatures.

We now return an empty list of choices as soon as we know there's no
signature to inspect. We still descend into the type arguments to
substitute `T`.

On
[yt-dlp](https://github.com/yt-dlp/yt-dlp/tree/3345986010358b98f4f702db4ee530aa5d2fd9dc),
instruction counts fell by 5.06% and peak RSS changed by less than 0.2%.

<!-- ty-pinned-project-instructions:start -->

| Cold `ty check` | Mean change | Largest change | Projects with a lower
median |
| --- | ---: | ---: | ---: |
| Instructions | −0.17% | −0.43% (OpenAI Python SDK) | 28/28 |
| Peak RSS | +0.07% | +0.66% (botocore) | 14/28 |

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages.

| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/481071f9f57999c484d5920b5d6ca8f97b132f20)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/c50d07cd8ccd7969416f06b0b464598299467f25)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,337,588,586 | 2,335,178,582.5 | -0.10% | -0.12% to -0.09% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,554,361,316.5 | 5,544,984,992 | -0.17% | -0.17% to -0.17% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 111,538,659,883.5 | 111,421,520,744.5 | -0.11% | -0.11% to -0.10% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,283,833,971 | 1,282,762,087 | -0.09% | -0.10% to -0.07% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,327,905,435.5 | 1,325,781,344.5 | -0.16% | -0.17% to -0.16% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,103,086,201 | 20,057,185,062.5 | -0.22% | -0.24% to -0.20% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,250,344,268 | 2,246,702,590 | -0.16% | -0.18% to -0.15% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,736,888,153 | 3,731,740,943 | -0.14% | -0.14% to -0.13% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,421,166,725 | 67,326,770,113.5 | -0.14% | -0.15% to -0.13% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,172,782,357.5 | 1,171,360,260.5 | -0.12% | -0.14% to -0.10% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 6,826,498,825.5 | 6,799,322,002 | -0.40% | -0.42% to -0.39% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,237,346,078 | 2,233,803,557.5 | -0.16% | -0.18% to -0.13% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,583,902,376.5 | 14,550,005,940 | -0.23% | -0.24% to -0.23% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,946,848,317.5 | 1,944,419,371.5 | -0.12% | -0.14% to -0.11% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,705,204,919 | 9,692,726,774.5 | -0.13% | -0.13% to -0.12% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,956,055,077 | 30,910,785,716.5 | -0.15% | -0.15% to -0.14% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,686,320,570.5 | 10,640,014,371 | -0.43% | -0.44% to -0.42% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,046,613,729.5 | 6,038,812,676 | -0.13% | -0.14% to -0.13% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 3,000,546,057.5 | 2,996,172,525 | -0.14% | -0.15% to -0.14% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,274,589,237.5 | 10,263,091,931.5 | -0.11% | -0.12% to -0.11% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,154,355,340 | 2,152,091,355.5 | -0.10% | -0.11% to -0.10% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,452,344,581 | 3,448,006,661.5 | -0.12% | -0.13% to -0.12% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 23,738,113,121 | 23,654,786,812 | -0.35% | -0.36% to -0.34% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 10,785,613,117 | 10,762,187,980 | -0.22% | -0.22% to -0.21% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,123,899,619.5 | 6,119,134,668 | -0.08% | -0.08% to -0.08% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,497,986,311.5 | 36,394,688,829 | -0.28% | -0.29% to -0.28% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,426,650,385 | 6,417,058,335 | -0.15% | -0.15% to -0.15% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 69,190,882,669 | 69,118,174,943 | -0.10% | -0.11% to -0.10% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| +0.25 (+0.23%) | 12/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.31 (+0.17%) | 12/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.03 (0.00%) | 7/16 | −0.08 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +0.08 (+0.11%) | 9/16 | +0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.09 (−0.11%) | 4/16 | −0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +1.37 (+0.27%) | 10/16 | −0.16 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| +0.02 (+0.01%) | 8/16 | +0.23 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.88 (−0.46%) | 6/16 | −0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −0.21 (−0.02%) | 6/16 | +0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| −0.04 (−0.04%) | 7/16 | +0.33 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +0.76 (+0.33%) | 10/16 | +0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.42 (−0.35%) | 7/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.09 (−0.03%) | 6/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.44 (+0.43%) | 10/16 | 0.00 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.03 (−0.01%) | 7/16 | 0.00 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −0.10 (−0.02%) | 6/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.07 (−0.02%) | 8/16 | −0.28 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.35 (−0.17%) | 7/16 | −0.08 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| +0.35 (+0.30%) | 12/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| +0.35 (+0.13%) | 10/16 | +0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.70 (+0.66%) | 12/16 | +0.61 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.04 (−0.03%) | 6/16 | +0.04 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| +0.50 (+0.09%) | 9/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 0.00 (0.00%) | 8/16 | +0.21 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +0.44 (+0.36%) | 10/16 | −0.17 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −0.05 (−0.01%) | 7/16 | +0.04 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.30 (+0.15%) | 12/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −0.08 (−0.01%) | 8/16 | −0.13 | 0.00 (0.00%) | 0.00 (0.00%) |

</details>

<!-- ty-pinned-project-instructions:end -->
2026-12-01 16:32:19 -05:00
Charlie Marsh 40955c77be [ty] Extract ParamSpec choice collection from type specialization (#31212)
## Summary

This PR extracts the logic for collecting `ParamSpec` choices into a
helper. No behavior changes, just makes #31195 easier to review (since
that PR adds an early return).
2026-12-01 16:32:18 -05:00
Victorien 1b6e76ab88 [ty] Preserve NewType when solving Self through a protocol (#31211) 2026-12-01 21:26:56 +00:00
Charlie Marsh de9a45abc1 [ty] Avoid resolving the document URI for each semantic token (#30669)
## Summary

When we open Pygments’ Lasso builtin table and request semantic tokens,
ty now executes 14.11% fewer instructions from server startup to
shutdown.

That one request returns 5,317 tokens. Today, for each token, we look up
the source text and line index and convert the same file path to a URI.
We immediately discard the URI because the editor already knows which
document it asked us to highlight.

We now create one `RangeConverter` per request. It reuses the source
text and line index and only resolves a URI when the caller needs one.
Semantic tokens, document highlights, folding ranges, and hierarchical
document symbols all use `to_local_range` to get positions relative to
the document or notebook cell. We still check for cancellation on each
range so edits can interrupt the request.

| Editor session | Change in instructions | Paired range | Peak RSS
(MiB) |
| --- | ---: | ---: | ---: |
| [Pygments’ Python
lexer](https://github.com/pygments/pygments/blob/cfca62e6e95136e48a255e8cbffb0bbe1d98456c/pygments/lexers/python.py)
| −4.29% | −4.30% to −4.27% | 53.8 → 53.8 |
| [Pygments’ Lasso builtin
table](https://github.com/pygments/pygments/blob/cfca62e6e95136e48a255e8cbffb0bbe1d98456c/pygments/lexers/_lasso_builtins.py)
| −14.11% | −14.17% to −14.09% | 46.0 → 46.2 |
2026-12-01 15:41:04 -05:00
Charlie Marsh 055bc9d1d9 [ty] Check subscript assignments on negated types (#30011)
## Summary

Today, adding an `is not None` check makes an `invalid-assignment` error
disappear in ty.

```python
def write(out: object) -> None:
    out[0] = 1  # error: [invalid-assignment]
    if out is not None:
        out[0] = 1  # No error
```

Inside the `if`, we narrow `out` to `~None`. This is equivalent to
`object & ~None`, but we leave the `object` implicit.

When checking a subscript assignment, we look for a positive element of
the intersection that supports `__setitem__`. Here, there are no
explicit positive elements, so we skip the check entirely. We also skip
inferring the types of the index and value, which trips an assertion in
debug builds.

We now fall back to `object` in this case, just as we do for subscript
reads. Since `object` doesn't define `__setitem__`, we report
`invalid-assignment` on both lines.

The [ecosystem
check](https://github.com/astral-sh/ruff/pull/30011#issuecomment-6620456227)
now flags the same [two slice assignments in
`array_api_compat`](https://github.com/scikit-learn/scikit-learn/blob/d5a61d1149cb94a936d4b32212330f4ba8f24ce0/sklearn/externals/array_api_compat/torch/linalg.py#L85-L107)
in both scikit-learn and SciPy.

<!-- ty-pinned-project-instructions:start -->

Measured 22 of 28 projects.

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.

| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/f4460e6a246c3c5946c378a493a4b0477f96b5b6)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/64ad0f4432bc25503eb5590c0d33348adb1f7133)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
(inconclusive) | 5,520,030,120 | 5,519,734,639 | 0.00% | -0.01% to 0.00%
|
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
(inconclusive) | 1,276,799,329.5 | 1,276,831,914.5 | 0.00% | 0.00% to
+0.01% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
(inconclusive) | 2,228,216,697 | 2,228,247,302.5 | 0.00% | -0.01% to
0.00% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
(inconclusive) | 3,700,911,803 | 3,700,863,299 | 0.00% | -0.01% to 0.00%
|
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
(inconclusive) | 67,020,678,458.5 | 67,021,118,877 | 0.00% | 0.00% to
0.00% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
(inconclusive) | 1,173,461,193.5 | 1,173,469,899.5 | 0.00% | -0.01% to
0.00% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 6,848,360,174.5 | 6,848,472,121 | 0.00% | 0.00% to
0.00% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
(inconclusive) | 2,219,922,569.5 | 2,219,876,593.5 | 0.00% | -0.01% to
+0.01% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
(inconclusive) | 14,424,050,600.5 | 14,424,529,543 | 0.00% | 0.00% to
+0.01% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
(inconclusive) | 1,937,265,850.5 | 1,937,238,641 | 0.00% | -0.01% to
0.00% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
(inconclusive) | 9,675,889,910.5 | 9,676,125,165.5 | 0.00% | -0.01% to
+0.01% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
(inconclusive) | 30,782,177,712 | 30,781,433,537 | 0.00% | -0.01% to
0.00% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
(inconclusive) | 10,589,722,261 | 10,589,792,313.5 | 0.00% | 0.00% to
0.00% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
(inconclusive) | 6,001,224,061.5 | 6,001,333,347 | 0.00% | 0.00% to
0.00% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
(inconclusive) | 2,981,316,229 | 2,981,343,761.5 | 0.00% | 0.00% to
0.00% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
(inconclusive) | 10,248,763,240.5 | 10,248,399,560 | 0.00% | 0.00% to
0.00% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
(inconclusive) | 2,148,555,675 | 2,148,560,003.5 | 0.00% | 0.00% to
0.00% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
(inconclusive) | 3,430,920,927 | 3,430,935,373.5 | 0.00% | 0.00% to
0.00% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
(inconclusive) | 23,607,686,762.5 | 23,607,918,625.5 | 0.00% | -0.01% to
0.00% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
(inconclusive) | 10,718,082,586 | 10,717,986,927 | 0.00% | -0.01% to
0.00% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
(inconclusive) | 6,076,631,621 | 6,076,392,380.5 | 0.00% | -0.01% to
0.00% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
(inconclusive) | 6,384,670,422.5 | 6,384,635,228.5 | 0.00% | 0.00% to
0.00% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI. A dash marks a pending measurement.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| — | — | — | 0.00 (0.00%) | — |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.12 (−0.07%) | 7/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| — | — | — | 0.00 (0.00%) | — |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.29 (−0.41%) | 7/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| — | — | — | 0.00 (0.00%) | — |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| — | — | — | 0.00 (0.00%) | — |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.63 (−0.49%) | 6/16 | −0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| +0.47 (+0.25%) | 10/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +0.08 (+0.01%) | 9/16 | +0.24 | — | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.29 (+0.34%) | 12/16 | −0.07 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +1.13 (+0.51%) | 10/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| +0.27 (+0.23%) | 8/16 | −0.14 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| +0.03 (+0.01%) | 8/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.48 (+0.48%) | 11/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.19 (−0.07%) | 3/16 | +0.11 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +0.42 (+0.07%) | 12/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.03 (−0.01%) | 7/16 | −0.21 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| +0.06 (+0.03%) | 10/16 | −0.05 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.15 (−0.13%) | 7/16 | 0.00 | — | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.21 (−0.08%) | 6/16 | +0.18 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 0.00 (0.00%) | 8/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.10 (−0.07%) | 6/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.15 (−0.03%) | 7/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.12 (−0.04%) | 5/16 | +0.19 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −0.03 (−0.03%) | 7/16 | −0.18 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| — | — | — | 0.00 (0.00%) | — |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.08 (−0.04%) | 6/16 | −0.14 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| — | — | — | 0.00 (0.00%) | — |

</details>

<!-- ty-pinned-project-instructions:end -->
2026-12-01 14:59:23 -05:00
Charlie Marsh 334db86a21 [ty] Remove two Salsa tests for comparisons and protocol methods (#31134)
## Summary

We remove the tests that change the return type of a reflected
comparison method across edits
([#31086](https://github.com/astral-sh/ruff/pull/31086#discussion_r4736070625))
and check which Salsa queries run when a protocol method is missing
([#31062](https://github.com/astral-sh/ruff/pull/31062#discussion_r4736090430)).
The mdtests still cover reflected comparisons and whether a callable
returned by `__getattr__` satisfies a protocol method.
2026-12-01 14:53:42 -05:00
Charlie MarshandCharlie Marsh 2d98a75ba5 [ty] Skip lambda bodies when collecting loop bindings (#31150)
## Summary

ty reports that `reset` conflicts with an instance slot at the `for`
statement below. It then reports a missing attribute when we assign to
`Queue().reset`.

```py
class Queue:
    __slots__ = ("reset",)

    for _ in (1,):
        push = lambda: (reset := 1)

Queue().reset = 1  # Valid
```

When we collect the names a loop can bind, we walk into the lambda body
and record a binding for `reset` in the class. That suppresses the slot
descriptor, even though `reset` is local to the lambda.

We now skip the lambda body and visit its parameter defaults. For
example, in `lambda arg=(value := 1): (result := arg)`, only `value` is
bound in the enclosing scope.

The bug surfaced while testing #30108, where renaming the lambda could
change the diagnostic for nested loops.

---------

Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
2026-12-01 19:33:48 +00:00
Charlie Marsh f4460e6a24 [ty] Share the operands of opposite redundancy checks (#31182)
## Summary

When we simplify `A | B`, we often check for redundancy in both
directions. If `B` inherits from `A`, we can drop `B` but have to keep
`A`. Today we intern `(A, B)` and `(B, A)` separately in Salsa to
distinguish the two checks, so we store the same operands twice.

We now order the types by hash so both checks can share one interned
pair. Each direction still has its own Salsa query, so we compute each
answer on demand and track its dependencies and cycles independently. If
the hashes collide, Salsa compares the full types and we store two pairs
as before.

<!-- ty-pinned-project-instructions:start -->

| Cold `ty check` | Mean change | Largest change | Projects with a lower
median |
| --- | ---: | ---: | ---: |
| Instructions | −0.22% | −0.47% (NumPy) | 28/28 |
| Peak RSS | −0.84% | −5.58% (Pydantic) | 27/28 |

We measured the [fork
revision](https://github.com/charliermarsh/ruff-dev/commit/a2da9fc65a267840953917ab96b894e7d0d80f01).
This PR has the same production code.

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages.

| Project | [Base
instructions](https://github.com/charliermarsh/ruff-dev/commit/f36e1976280a364318890d3174ddce7da5cf69d8)
| [PR
instructions](https://github.com/charliermarsh/ruff-dev/commit/a2da9fc65a267840953917ab96b894e7d0d80f01)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,333,335,411.5 | 2,329,439,574.5 | -0.17% | -0.17% to -0.16% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,567,436,179 | 5,556,731,278 | -0.19% | -0.19% to -0.19% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 111,346,049,867 | 110,993,775,505.5 | -0.32% | -0.32% to -0.31% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,280,946,040.5 | 1,279,281,379.5 | -0.12% | -0.17% to -0.10% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,327,914,050 | 1,325,032,959 | -0.22% | -0.23% to -0.21% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,076,409,508 | 20,038,898,462.5 | -0.19% | -0.19% to -0.17% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,246,591,319 | 2,243,079,848.5 | -0.15% | -0.19% to -0.13% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,732,876,002.5 | 3,724,139,871 | -0.23% | -0.24% to -0.23% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,347,165,487 | 67,183,220,726 | -0.24% | -0.25% to -0.23% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,173,951,753.5 | 1,171,287,383 | -0.24% | -0.25% to -0.20% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 6,951,456,472 | 6,918,751,064 | -0.47% | -0.48% to -0.45% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,235,619,738 | 2,232,693,341 | -0.12% | -0.14% to -0.12% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,553,897,804.5 | 14,495,687,966.5 | -0.40% | -0.41% to -0.39% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,950,983,457 | 1,946,659,686 | -0.22% | -0.23% to -0.22% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,691,376,070.5 | 9,671,715,190 | -0.20% | -0.20% to -0.20% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,902,373,278.5 | 30,827,462,609 | -0.24% | -0.25% to -0.24% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,700,340,724 | 10,683,918,479 | -0.15% | -0.16% to -0.15% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,037,381,182.5 | 6,025,771,235.5 | -0.19% | -0.20% to -0.18% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 2,996,787,279.5 | 2,990,248,848.5 | -0.22% | -0.23% to -0.21% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,262,756,841 | 10,242,541,939 | -0.20% | -0.20% to -0.19% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,158,770,161.5 | 2,153,684,616 | -0.24% | -0.26% to -0.22% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,445,887,309 | 3,438,423,296 | -0.21% | -0.22% to -0.21% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 23,722,355,535.5 | 23,700,111,232 | -0.09% | -0.10% to -0.09% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 10,775,682,959 | 10,754,546,165.5 | -0.20% | -0.20% to -0.19% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,090,628,318.5 | 6,089,749,806 | -0.01% | -0.02% to -0.01% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,474,716,742 | 36,416,470,479 | -0.16% | -0.16% to -0.15% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,440,789,136 | 6,421,231,514 | -0.30% | -0.31% to -0.30% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 69,140,577,984.5 | 68,901,583,349.5 | -0.35% | -0.35% to -0.34% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −0.39 (−0.36%) | 5/16 | −0.36 | −0.23 (−0.38%) | −0.29 (−0.45%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.64 (−0.35%) | 3/16 | −0.73 | −1.08 (−0.88%) | −1.18 (−0.84%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −5.71 (−0.18%) | 0/16 | −4.88 | −7.69 (−0.29%) | −8.57 (−0.27%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.19 (−0.26%) | 6/16 | −0.09 | −0.12 (−0.48%) | −0.36 (−1.01%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.20 (−0.26%) | 6/16 | +0.07 | −0.24 (−0.68%) | −0.26 (−0.67%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| −10.53 (−2.05%) | 1/16 | −8.15 | −7.20 (−1.81%) | −8.03 (−1.78%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −1.03 (−0.79%) | 4/16 | −0.67 | −0.75 (−0.94%) | −0.84 (−1.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.58 (−0.30%) | 7/16 | −0.05 | −0.35 (−0.26%) | −0.37 (−0.26%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −10.58 (−0.75%) | 0/16 | −10.61 | −10.24 (−0.89%) | −11.79 (−0.85%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.21 (+0.25%) | 9/16 | −0.22 | −0.17 (−0.40%) | −0.18 (−0.42%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −1.02 (−0.46%) | 4/16 | −1.65 | −1.32 (−0.89%) | −1.36 (−0.76%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −2.02 (−1.70%) | 2/16 | −1.62 | −1.69 (−2.44%) | −1.75 (−2.35%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −2.28 (−0.65%) | 2/16 | −2.53 | −2.69 (−1.04%) | −3.02 (−0.98%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.74 (−0.72%) | 5/16 | −0.41 | −0.22 (−0.42%) | −0.24 (−0.42%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −1.64 (−0.60%) | 0/16 | −1.73 | −1.60 (−0.82%) | −2.01 (−0.88%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −4.92 (−0.79%) | 0/16 | −5.12 | −4.83 (−1.05%) | −6.44 (−1.11%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −3.36 (−1.19%) | 0/16 | −3.25 | −3.40 (−1.63%) | −3.69 (−1.53%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.40 (−0.19%) | 6/16 | −0.43 | −0.63 (−0.43%) | −0.65 (−0.40%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −1.07 (−0.92%) | 0/16 | −0.82 | −0.39 (−0.63%) | −0.60 (−0.80%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −1.11 (−0.43%) | 6/16 | −1.38 | −1.36 (−0.76%) | −1.86 (−0.85%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| −0.54 (−0.51%) | 6/16 | −0.49 | −0.51 (−0.86%) | −0.54 (−0.84%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.15 (−0.11%) | 6/16 | −0.22 | −0.52 (−0.61%) | −0.58 (−0.60%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −5.22 (−0.96%) | 0/16 | −5.63 | −5.34 (−1.25%) | −5.81 (−1.20%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −2.22 (−0.85%) | 1/16 | −1.83 | −1.60 (−0.89%) | −1.89 (−0.88%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −6.83 (−5.58%) | 0/16 | −7.25 | −6.91 (−9.76%) | −7.32 (−8.75%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −9.97 (−1.81%) | 0/16 | −9.95 | −9.28 (−2.16%) | −10.53 (−1.97%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.60 (−0.29%) | 2/16 | −0.61 | −0.60 (−0.41%) | −0.62 (−0.37%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −9.02 (−0.62%) | 0/16 | −6.71 | −7.03 (−0.60%) | −8.07 (−0.57%) |

</details>

<!-- ty-pinned-project-instructions:end -->
2026-12-01 18:05:46 +00:00
Charlie Marsh 91486ce245 [ty] Keep declared variance with each generic parameter (#31173)
## Summary

When we substitute a type for `T` in `list[T]`, we look up the variance
of `list`’s type parameter to decide how to transform the argument. The
parameter is always invariant, but we go through Salsa twice to find
that out on every visit.

We now store each parameter’s declared variance alongside the type
variable in `GenericContext`. If the parameter has no declared variance,
we still infer it at the point of use. Inferring it earlier can change
the order in which we resolve recursive annotations.

<!-- ty-pinned-project-instructions:start -->

| Cold `ty check` | Mean change | Largest change | Projects with a lower
median |
| --- | ---: | ---: | ---: |
| Instructions | −0.17% | −0.48% (OpenAI Python SDK) | 28/28 |
| Peak RSS | −0.06% | −1.10% (isort) | 16/28 |

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages.

| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/d7fefd975d13692af9b988ec52f076ba22b1f960)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/5f4c05819a3a79aff45415f2396344759037697d)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,337,838,845 | 2,336,942,698 | -0.04% | -0.04% to -0.03% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,553,270,997.5 | 5,544,082,351 | -0.16% | -0.17% to -0.16% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 111,390,708,084.5 | 111,248,059,700.5 | -0.13% | -0.13% to -0.13% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,280,045,870.5 | 1,279,834,819 | -0.02% | -0.02% to -0.01% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,325,747,783 | 1,323,727,796 | -0.15% | -0.16% to -0.15% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,051,394,182 | 20,001,520,405 | -0.25% | -0.25% to -0.25% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,247,335,573 | 2,240,517,384 | -0.31% | -0.31% to -0.30% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,736,484,563.5 | 3,727,924,070.5 | -0.23% | -0.23% to -0.23% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,401,933,639.5 | 67,320,648,293.5 | -0.12% | -0.13% to -0.12% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,183,831,026 | 1,182,848,443 | -0.08% | -0.12% to -0.08% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 6,952,473,585 | 6,928,958,040.5 | -0.33% | -0.38% to -0.30% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,222,661,566 | 2,220,521,834.5 | -0.09% | -0.11% to -0.09% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,581,814,288 | 14,520,470,882.5 | -0.42% | -0.42% to -0.42% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,954,263,340.5 | 1,953,083,011 | -0.06% | -0.07% to -0.06% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,689,033,816.5 | 9,676,642,966 | -0.13% | -0.13% to -0.12% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,761,489,308.5 | 30,708,115,260 | -0.17% | -0.18% to -0.17% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,682,302,598.5 | 10,631,069,757.5 | -0.48% | -0.48% to -0.47% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,036,793,352 | 6,031,701,164.5 | -0.08% | -0.09% to -0.08% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 2,999,376,256 | 2,994,857,448 | -0.15% | -0.15% to -0.15% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,294,560,807.5 | 10,285,278,923.5 | -0.09% | -0.09% to -0.09% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,159,264,947.5 | 2,157,434,048 | -0.09% | -0.09% to -0.07% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,441,993,413.5 | 3,437,948,014.5 | -0.12% | -0.12% to -0.12% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 23,716,931,530.5 | 23,675,672,626.5 | -0.18% | -0.18% to -0.16% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 10,782,084,785.5 | 10,761,075,297 | -0.20% | -0.20% to -0.19% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,077,964,846 | 6,071,171,243.5 | -0.11% | -0.12% to -0.11% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,563,191,515.5 | 36,435,118,674.5 | -0.35% | -0.36% to -0.35% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,436,436,410.5 | 6,427,986,435.5 | -0.13% | -0.13% to -0.13% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 69,098,397,209 | 69,013,469,746.5 | -0.12% | -0.13% to -0.12% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI. The ordered-map estimate counts the
size of a key-value pair times capacity. The larger value can raise that
estimate even when it fits in padding in the allocated entry.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −0.25 (−0.23%) | 6/16 | −0.12 | +0.01 (+0.02%) | +0.01 (+0.02%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.11 (+0.06%) | 11/16 | −0.17 | +0.03 (+0.03%) | +0.03 (+0.02%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.05 (0.00%) | 7/16 | +0.20 | +0.26 (+0.01%) | +0.26 (+0.01%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.77 (−1.10%) | 5/16 | −0.13 | +0.01 (+0.02%) | +0.01 (+0.01%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.29 (−0.37%) | 5/16 | +0.09 | +0.01 (+0.03%) | +0.01 (+0.02%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +2.27 (+0.44%) | 11/16 | +0.11 | +0.06 (+0.02%) | +0.06 (+0.01%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.07 (−0.06%) | 7/16 | +0.24 | +0.01 (+0.02%) | +0.01 (+0.02%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| +0.28 (+0.15%) | 9/16 | −0.09 | +0.01 (+0.01%) | +0.01 (+0.01%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +0.55 (+0.04%) | 10/16 | −0.02 | +0.19 (+0.02%) | +0.19 (+0.01%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| −0.05 (−0.06%) | 4/16 | −0.04 | 0.00 (+0.01%) | 0.00 (+0.01%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −0.11 (−0.05%) | 7/16 | −0.29 | +0.09 (+0.06%) | +0.09 (+0.05%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.17 (−0.14%) | 7/16 | −0.23 | +0.01 (+0.01%) | +0.01 (+0.01%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| +0.19 (+0.06%) | 10/16 | +0.09 | +0.08 (+0.03%) | +0.08 (+0.03%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.71 (−0.69%) | 7/16 | −0.13 | +0.01 (+0.02%) | +0.01 (+0.02%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.29 (−0.11%) | 5/16 | −0.03 | +0.03 (+0.02%) | +0.03 (+0.01%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +0.20 (+0.03%) | 11/16 | +0.17 | +0.10 (+0.02%) | +0.10 (+0.02%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| +0.25 (+0.09%) | 10/16 | −0.14 | +0.03 (+0.01%) | +0.03 (+0.01%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.13 (−0.06%) | 5/16 | −0.01 | +0.02 (+0.01%) | +0.02 (+0.01%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.03 (−0.03%) | 8/16 | +0.19 | +0.02 (+0.03%) | +0.02 (+0.02%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.22 (−0.08%) | 7/16 | −0.04 | +0.03 (+0.02%) | +0.03 (+0.01%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.14 (+0.13%) | 8/16 | −0.12 | +0.01 (+0.02%) | +0.01 (+0.01%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| +0.05 (+0.04%) | 9/16 | +0.05 | +0.01 (+0.01%) | +0.01 (+0.01%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.20 (−0.04%) | 6/16 | +0.14 | +0.08 (+0.02%) | +0.08 (+0.02%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.11 (−0.04%) | 5/16 | −0.15 | +0.04 (+0.02%) | +0.04 (+0.02%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +0.26 (+0.21%) | 10/16 | +0.10 | +0.01 (+0.02%) | +0.01 (+0.01%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| +0.34 (+0.06%) | 10/16 | −0.02 | +0.12 (+0.03%) | +0.12 (+0.02%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.05 (+0.02%) | 9/16 | −0.25 | +0.03 (+0.02%) | +0.03 (+0.02%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −0.26 (−0.02%) | 6/16 | −0.43 | +0.10 (+0.01%) | +0.10 (+0.01%) |

</details>

<!-- ty-pinned-project-instructions:end -->

On
[yt-dlp](https://github.com/yt-dlp/yt-dlp/tree/da452a569fb3d04091468d920f9b9e68512e0373/yt_dlp),
which is outside the suite above, this PR reduced instruction counts by
7.18% in all four pairs.
2026-12-01 13:04:08 -05:00
Charlie Marsh ac6f4ce268 [ty] Fix a panic on nested global and nonlocal writes in classes (#31205)
## Summary

ty can panic when a method assigns to a global or nonlocal variable.

```py
x = 0

class C:
    def update(self):
        global x
        x = 1
```

In #31143, we started removing writes like `x = 1` from the class
namespace when we leave the class body. They can affect reads of `x` in
the class body, but they don't define `C.x`.

After #31171, we could finish the class's use-def map before removing
those writes. We now process nested declarations before finishing the
map.
2026-12-01 17:34:06 +00:00
Micha Reiser a203fb8661 Update the CodSpeed GitHub Action to v5.8.1 (#31204)
## Summary

Update the CodSpeed action from v5.6.3 to
[v5.8.1](https://github.com/CodSpeedHQ/action/releases/tag/v5.8.1) in
all four benchmark jobs. This release retries failed GitHub release
downloads, including HTTP 618 errors from expired links.

Local workflow validation and security checks passed.
2026-12-01 18:24:12 +01:00
Charlie MarshandCharlie Marsh 6c0638c7ec [ty] Finish use-def maps when leaving independent scopes (#31171)
## Summary

Today we box each scope’s `UseDefMapBuilder` to avoid copying it when
the scope table grows. We finish all the maps at the end of the file, so
a stub with hundreds of methods keeps hundreds of builders alive at
once.

We now finish most use-def maps as we leave their scopes. In the stub,
we can finish one method’s map and reuse the same inline slot for the
next method. We only box a builder when we enter a child scope or need
to keep it after leaving the scope.

We still need the builder if a later assignment can update an enclosing
snapshot or if a comprehension’s parent needs to check whether a `:=`
target was bound.

<!-- ty-pinned-project-instructions:start -->

| Cold `ty check` | Mean change | Largest decrease | Projects with a
decrease |
| --- | ---: | ---: | ---: |
| Instructions | −0.28% | −0.56% (Prefect) | 28/28 |
| Peak RSS | −0.35% | −1.59% (pandas) | 25/28 |

<details>
<summary>Instruction counts by project</summary>

Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages.

| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/d7fefd975d13692af9b988ec52f076ba22b1f960)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/b7a9cde3d694d36acdf5ecba83b4e0ae3631dc2b)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,334,357,964.5 | 2,323,779,926.5 | -0.45% | -0.46% to -0.45% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,551,932,347 | 5,538,299,813.5 | -0.25% | -0.25% to -0.24% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 111,464,080,391.5 | 111,205,655,140 | -0.23% | -0.23% to -0.23% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,281,812,413 | 1,278,722,324 | -0.24% | -0.25% to -0.22% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,328,215,736 | 1,323,697,179 | -0.34% | -0.35% to -0.32% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,058,360,281.5 | 19,985,457,234 | -0.36% | -0.39% to -0.34% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,247,028,812.5 | 2,236,210,296 | -0.48% | -0.54% to -0.47% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,744,108,015 | 3,723,261,699 | -0.56% | -0.56% to -0.55% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,448,418,850.5 | 67,263,666,484.5 | -0.27% | -0.28% to -0.27% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,182,438,200.5 | 1,176,932,900.5 | -0.47% | -0.48% to -0.45% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 6,917,539,356 | 6,897,412,077.5 | -0.29% | -0.30% to -0.28% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,232,522,701 | 2,223,477,910.5 | -0.41% | -0.41% to -0.40% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,600,493,269.5 | 14,573,838,515.5 | -0.18% | -0.19% to -0.18% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,950,683,127.5 | 1,945,474,643 | -0.27% | -0.27% to -0.26% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,700,753,399 | 9,680,875,288 | -0.20% | -0.21% to -0.20% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,942,514,779 | 30,883,691,936.5 | -0.19% | -0.20% to -0.19% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,668,473,160.5 | 10,653,578,853 | -0.14% | -0.14% to -0.14% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,046,961,066.5 | 6,025,572,820 | -0.35% | -0.36% to -0.35% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 2,996,913,938 | 2,988,588,486 | -0.28% | -0.28% to -0.28% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,268,039,255 | 10,247,304,656 | -0.20% | -0.20% to -0.19% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,162,780,217 | 2,155,185,648.5 | -0.35% | -0.35% to -0.35% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,446,937,891.5 | 3,436,056,079 | -0.32% | -0.32% to -0.31% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 23,721,086,554.5 | 23,664,835,164 | -0.24% | -0.26% to -0.23% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 10,781,581,328.5 | 10,759,036,395.5 | -0.21% | -0.21% to -0.21% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,097,788,917 | 6,090,631,567.5 | -0.12% | -0.12% to -0.11% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,523,025,053.5 | 36,475,127,130.5 | -0.13% | -0.13% to -0.13% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,439,778,661 | 6,425,265,359 | -0.23% | -0.23% to -0.22% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 69,165,443,557.5 | 69,026,891,356.5 | -0.20% | -0.20% to -0.20% |

</details>

<details>
<summary>Memory by project</summary>

Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI.

| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −1.17 (−1.06%) | 0/16 | −0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.30 (−0.17%) | 5/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.69 (−0.02%) | 1/16 | −0.43 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.99 (−1.41%) | 4/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.12 (−0.15%) | 8/16 | −0.24 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| −8.20 (−1.59%) | 5/16 | −0.28 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −1.41 (−1.07%) | 3/16 | −0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.70 (−0.37%) | 4/16 | −0.20 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +1.39 (+0.10%) | 15/16 | +1.61 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| −0.40 (−0.47%) | 7/16 | −0.05 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +1.91 (+0.85%) | 10/16 | +0.31 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.76 (−0.64%) | 3/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.30 (−0.09%) | 4/16 | +0.21 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.68 (−0.67%) | 3/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.14 (−0.05%) | 6/16 | −0.32 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +0.04 (+0.01%) | 8/16 | −0.39 | 0.00 (0.00%) | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −1.33 (−0.47%) | 1/16 | −0.46 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.36 (−0.18%) | 3/16 | +0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.33 (−0.29%) | 3/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.50 (−0.19%) | 6/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| −0.31 (−0.29%) | 5/16 | −0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.24 (−0.18%) | 5/16 | +0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −1.38 (−0.25%) | 5/16 | −0.29 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.37 (−0.14%) | 3/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −0.52 (−0.42%) | 3/16 | +0.21 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −0.21 (−0.04%) | 5/16 | −0.28 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.56 (−0.27%) | 2/16 | −1.24 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −2.21 (−0.15%) | 5/16 | −0.19 | 0.00 (0.00%) | 0.00 (0.00%) |

</details>

<!-- ty-pinned-project-instructions:end -->

---------

Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
2026-12-01 12:01:41 -05:00
481071f9f5 [pydoclint] Stop parsing parameters at unknown NumPy and Google section headings (DOC102) (#30148)
Closes #30137.

Stop collecting parameters at underlined NumPy-style section headings or
Google-style section headings ending in a colon, including unrecognized
headings. This prevents section names and their contents from being
reported as extraneous parameters. Indented headings within parameter
descriptions still leave later parameter declarations visible to the
rule.

Adds regression coverage.

---------

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Co-authored-by: Micha Reiser <micha@reiser.io>
2026-12-01 11:07:44 +00:00
Micha Reiser 09c25ac275 [ty] Prepare fixes and ignore comments in parallel (#31146)
## Summary

`ty check --fix` skips files with fixable diagnostics that have syntax
errors. To do this, ty calls `parsed_module` of every file with a
fixable diagnostic. This can result in a reparse because `check_file`
clears the AST of first-party modules. Today, this check is done on the
main `--fix` thread, sequentially.

This PR runs this check in parallel for every fixable file, which speeds
up `ty check --fix` with many files.

I considered whether we should parametrize `ty check --fix` instead and
skip clearing the AST. While this avoids throwing away work that we need
to repeat later, I decided against it because:

* Salsa should control when and why to clear a parsed module. That
means, we can't control this in the future when this becomes Salsa's
responsibility.
* Not clearing the ASTs can drastically increase peak memory usage
because we now retain all ASTs for the entire check.

## Benchmarks

Whether the optimization helps depends on how many files get fixed. It
can even be a small regression if there are only very few files.
However, it is a significant speedup when fixing many files, which is
why I thin this optimization is justified.

| Project | Command | Files edited | Median total before (s) | Median
total after (s) | Difference | Faster |
|---|---|---:|---:|---:|---:|---:|
| Home Assistant | `ty check --fix` | 16 | 6.258 | 6.276 | +0.017 s
(+0.3%) | 10/16 (62.5%) |
| Airflow | `ty check --fix` | 60 | 3.306 | 3.274 | −0.031 s (−0.9%) |
10/16 (62.5%) |
| Home Assistant | `ty check --add-ignore` | 6,668 | 11.922 | 10.654 |
−1.268 s (−10.6%) | 6/6 (100%) |
| Airflow | `ty check --add-ignore` | 3,460 | 6.138 | 5.641 | −0.497 s
(−8.1%) | 6/6 (100%) |
| **Overall** | | | | | | **32/44 (72.7%)** |


## Alternatives

I also considered adding a `has_syntax_errors` flag to `ParsedModule` to
skip reparsing alltogether. While skipping reparsing is nice,
`--add-ignore` still requires the token stream, which requires parsing
the module. The end result was that both versions were about as fast on
my dev machine (limited to 8 workers).


Project | Command | Files edited | Parallel (s) | Flag (s) | Flag −
Parallel | Flag faster
-- | -- | -- | -- | -- | -- | --
Home Assistant | ty check --fix | 16 | 6.191 | 6.422 | +0.230 s (+3.7%)
| 0/6 (0%)
Airflow | ty check --fix | 60 | 3.317 | 3.356 | +0.039 s (+1.2%) | 2/6
(33.3%)
Home Assistant | ty check --add-ignore | 6,668 | 10.779 | 11.744 |
+0.965 s (+9.0%) | 0/6 (0%)
Airflow | ty check --add-ignore | 3,460 | 5.644 | 6.282 | +0.637 s
(+11.3%) | 0/6 (0%)
Overall |   |   |   |   |   | 2/24 (8.3%)

Which is why I preferred the parallel approach, as it avoids storing
more data (even if it fits into padding)
2026-12-01 11:42:06 +01:00
Micha Reiser b335aedf05 [ty] Recheck the project after applying fixes or adding ignore comments (#31145)
## Summary

`--fix` shows all remaining diagnostics and a counter for how many
diagnostics were fixed.

Today, `--fix` skips rechecking files that have no fixable diagnostics.
I assumed this was a safe performance optimization. But I didn't account
for sub diagnostics. A sub diagnostic can point to an arbitrary other
file and the range might change if we apply fixes to that file.

This PR changes `--fix` to run a full project check at the end. This
ensures that all ranges are updated after applying fixes. This comes at
a performance cost (3-5%), but simplifies the code a fair bit, because
we no longer need to carry-forward the diagnostics after fixing.

What made this slightly harder to fix is that I wanted to preserve
today's behavior that pressing Ctrl+C during the fix loop (or it's
rechecking after) exits quickly. Supporting this required changing how
we run the second project check. We now run it as part of the main loop,
where we already handle Ctrl+C. The alternative would have been to pass
a cancellation token to `project.check`. I decided against that because
it meant that `project.check` now had two different APIs for
cancellation.

Fixes astral-sh/ty#5026.

## Benchmarks

On the original project files, `ty check --fix` took **5.7% longer on
Home Assistant** (+410 ms) and **3.2% longer on Airflow** (+125 ms).
Individual paired runs varied from −0.8% to +9.4% and −2.3% to +7.5%,
respectively.

I suspect that we can get the regression down by seeing if we could add
some Salsa caching to narrow the invalidation. But that's out of the
scope of this PR and the regression is in the range of what I expected
for this fix (sometimes there's no regression at all).

These are median wall times from four pairs of runs with eight workers
on a RAM-backed filesystem. I alternated the run order and compared the
baseline (`77203ea552`) with a version that ran the final project check
synchronously. This PR schedules that same check in the background. Both
builds prepared edits serially.

| Project | Workload | Files edited | Baseline (s) | With recheck (s) |
Change | Final check (s) |
|---|---|---:|---:|---:|---:|---:|
| Home Assistant | `--fix` | 16 | 7.216 | 7.626 | +5.7% | 0.541 |
| Airflow | `--fix` | 60 | 3.896 | 4.021 | +3.2% | 0.266 |
| Home Assistant | `--add-ignore` | 6,668 | 14.122 | 13.951 | -1.2% |
0.133 |
| Airflow | `--add-ignore` | 3,460 | 7.037 | 7.446 | +5.8% | 0.053 |
| pandas-stubs | `--add-ignore` | 216 | 2.985 | 2.757 | -7.6% | 0.006 |
| PyTorch | `--add-ignore` | 1,703 | 14.467 | 14.182 | -2.0% | 0.066 |
| Home Assistant | Remove ignores | 6,668 | 12.592 | 12.506 | -0.7% |
0.107 |
| Airflow | Remove ignores | 3,460 | 6.557 | 6.793 | +3.6% | 0.038 |
| pandas-stubs | Remove ignores | 221 | 2.650 | 2.711 | +2.3% | 0.011 |
| PyTorch | Remove ignores | 1,703 | 13.483 | 13.644 | +1.2% | 0.064 |

The change compares the two whole-command medians. The final check is
included in the command time and measured by subtracting fix time from
combined fix and recheck time in each run. “Remove ignores” runs `--fix`
on the output of `--add-ignore` with only `unused-ignore-comment`
enabled.

## Notes for reviewers

I suggest reviewing this PR commit by commit.
2026-12-01 11:42:06 +01:00
Charlie Marsh fbabe4c5e1 [ty] Preserve literals outside a sequence when simplifying unions (#30996)
## Summary

ty rejects the call below because it drops both literals from the union.
`"aa"` is a sequence of `"a"` characters, but `"ab"` is still a valid
argument in its own right. Reversing the union members makes ty accept
the call.

```py
from collections.abc import Sequence
from typing import Literal

def f(x: Literal["aa", "ab"] | Sequence[Literal["a"]]): ...

f("ab")
```

When we add a sequence to a union that already contains string or bytes
literals, we now check each literal for redundancy. This also handles
sequences nested inside intersections. Previously we used the first
literal to decide whether to keep the entire group, so we could also
keep redundant literals when the first one fell outside the sequence.
2026-11-30 21:30:34 -05:00
Charlie Marsh 40f340b3e7 [ty] Make the match in DefinitionEntry::binding_kind exhaustive (#31183)
## Summary

As-is, the wildcard in `DefinitionEntry::binding_kind` gives any new
variant `BindingKind::Default`. We now match `DeclarationPart`,
`Undefined`, and `Deleted` explicitly, so adding a variant without
handling it here is a compile error.

Follow-up to [Alex's comment on
#31143](https://github.com/astral-sh/ruff/pull/31143#discussion_r4746576727).
2026-11-30 20:58:34 -05:00
Charlie MarshandCharlie Marsh 00171fe5ef [ty] Exclude nested global and nonlocal writes from class namespaces (#31143)
## Summary

Calling `update()` changes the value of `x` that we read in the class
body, but it doesn't create a `C.x` attribute.

```py
x = 0

class C:
    def update():
        global x
        x = "changed"

    update()
    y = x

assert C.y == "changed"
assert "x" not in vars(C)
```

Since we don't track when `update` is called, we record a possible write
to `x` as soon as we see the function definition. Today we also treat
that write as a binding for `C.x`. If `C` inherits an attribute named
`x`, we can incorrectly include the global's type in the type of that
attribute.

We now remove these bindings for nested `global` and `nonlocal` writes
when we leave the class scope. Each read in the class body already has
its own snapshot of the bindings, so `y = x` still accounts for the
write.

Closes https://github.com/astral-sh/ty/issues/5024.

---------

Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
2026-11-30 20:44:27 -05:00
Alex Waygood a4b9d26a83 [ty] Clarify rule documentation for omitted type arguments and TypedDicts (#31155) 2026-11-30 23:50:40 +00:00
Ee Durbin 1ae938b57a Sync ruff-dev and promote approved pull requests to Ruff (#31177)
## Summary

Keep [ruff-dev](https://github.com/astral-sh/ruff-dev) synced with
Ruff’s `main` and promote drafts by marking them ready for review or
applying `bot:promote`. Promotion creates a branch and PR in Ruff,
assigns the promoter, and closes the source PR with a link upstream.
Follow-up pushes go to the branch in Ruff.

The sync, promotion, and parent-update workflows come from [uv at
c2f08ef](https://github.com/astral-sh/uv/tree/c2f08ef00e551b62857c44be96ae9e9de8269408/.github/workflows).
Their only substitutions are repository names, Ruff’s repository ID, and
the local `setup-ruff-workspace` action for `setup-uv-toolchain`. The
dispatcher and token service use the corresponding dev-fork rules.
Promotion uses a single short-lived token for Ruff and ruff-dev, pinned
to the automations installation. No dispatch route or token grant
enables promotion from ruff-security.

The port includes stacked parent handling, rejection recovery, and
opt-in `bot:automerge` for upstream writers. Separate
conflict-resolution automation is outside this PR. If a parent update
hits conflicts, resolve them manually after retargeting, even if the
recovery comment mentions automated rebasing.

## Rollout

1. Confirm the protections from [github-policies
#116](https://github.com/astral-sh/github-policies/pull/116) are
applied. Grant the automations app access to the fork and configure
`STS_API_URL` in its `automations` environment.
2. After merge, sync the fork once with a maintainer credential. The
token service reads the **target** repository’s policy, so the first
automatic sync can fail until the fork has this revision.

   ```sh
gh api --method POST repos/astral-sh/ruff-dev/merge-upstream -f
branch=main
gh label create bot:promote -R astral-sh/ruff-dev --color fef2c0
--description 'Promote this PR to Ruff'
   ```

The dispatcher also accepts `bot:automerge`. Create that label only if
automatic squash merging is desired. Ordinary promotion does not enable
auto-merge.

3. Enable Actions on the fork. For the initial CI trial, keep `ci.yaml`,
`promote-pull-request.yml`, and its reusable
`update-pull-request-parent.yml` helper active there. This exercises
normal draft checks without enabling the fork’s release, publishing, or
scheduled workflows. Sync runs in Ruff.

   ```sh
   gh api --paginate repos/astral-sh/ruff-dev/actions/workflows \
--jq '.workflows[] | select(.state == "active" and .path !=
".github/workflows/promote-pull-request.yml" and .path !=
".github/workflows/update-pull-request-parent.yml" and .path !=
".github/workflows/ci.yaml") | .id' |
while read -r id; do gh workflow disable "$id" -R astral-sh/ruff-dev;
done
   gh workflow enable promote-pull-request.yml -R astral-sh/ruff-dev
gh workflow enable update-pull-request-parent.yml -R astral-sh/ruff-dev
   gh workflow enable ci.yaml -R astral-sh/ruff-dev
   ```

4. Dispatch `sync-ruff-dev.yml` in Ruff and confirm the two main
branches agree. Open a draft in the fork, check that CI starts, then
mark it ready. Verify the upstream SHA, the link on the closed source
PR, and fresh upstream checks. Promotion does not wait for fork CI.

5. Compare queue time and time to required checks on the first few
drafts and their promoted commits. Sync pushes to `main` also run CI and
populate Rust caches. If the extra runs are too slow or noisy, disable
CI in the fork with `gh workflow disable ci.yaml -R astral-sh/ruff-dev`.
Promotion and upstream CI continue independently.

## Verification

Compared all three workflows byte for byte against the pinned uv
revision after substituting repository names, the ID, and the setup
action. Workflow linting, both service policy parsers, and dispatcher
route checks passed. Local runs of the copied shell steps against a mock
GitHub CLI exercised sync, ready and label promotion, auto-merge
approval and denial, stale commits, and branch collisions. Live sync and
promotion require rollout.
2026-11-30 22:57:19 +00:00
Charlie Marsh f36e197628 [ty] Reserve space for known overloads when inferring call arguments (#31164)
## Summary

On NumPy, reserving space for overloads reduced the bytes ty requested
from the allocator by 1.34%, about 34 MiB per full check.

When we infer call arguments, we collect a binding and a type-context
cache for each candidate overload. Even when we have a candidate set, we
grow the list as we visit the overloads. Moving the cache entries makes
each reallocation expensive.

We now use the number of candidates as a capacity hint. A single entry
still fits inline. If a binding contributes a fallback overload, the
list can grow as before.
2026-11-30 17:02:24 -05:00
Alex Waygood 30d2b7af92 [ty] Correct the documentation for six diagnostic rules (#31142) 2026-11-30 20:56:51 +00:00
Alex Waygood e0f107e806 [ty] Correct inaccuracies and imprecision in configuration and CLI documentation (#31157)
Detailed rationale for each change is found in inline review comments.
2026-11-30 15:32:33 -05:00
Charlie Marsh d7fefd975d [ty] Skip unrelated strings when finding references (#30681)
## Summary

Today, finding references to `C` can require inferring the entire body
of `greet` just to determine whether its docstring is a type annotation.

```python
class C: ...

items: "list['𝒞']"  # 𝒞 refers to C

def greet(name):
    """Say hello."""
    print(f"Hello, {name}!")
```

We already skip files that can’t contain the name we’re looking for. We
now apply the same check to individual string literals before asking the
type checker whether they’re annotations. This lets us skip the
docstring and still find `𝒞` in the nested annotation, since Python
normalizes `𝒞` to `C`. Rename and document highlights use the same
search.

In Pydantic 2.14.4, the language server used 84.87–84.91% fewer
instructions to open `main.py`, report diagnostics, and find references
to `_typing_extra`. We found the same 61 locations across 12 files.

Document highlights only search the current file. Highlighting
`_typing_extra` used 94.62% fewer instructions before we requested
diagnostics for `main.py`. Once we’d requested diagnostics, there was
almost no difference. In mypy-boto3-ec2 1.44.8, highlighting
`NotRequired` in `type_defs.pyi` before diagnostics used 65.31% fewer
instructions.
2026-11-30 15:20:33 -05:00
Charlie Marsh 41908af5a7 [ty] Allocate parser scratch buffers on demand for standalone expressions (#31159)
## Summary

A full ty check of the Sentry Python SDK requested 3.85% fewer bytes
from the allocator, about 15 MiB per check. The project contains more
than 4,000 quoted annotations.

Each time we parse an annotation like `"Client"`, we reserve scratch
space for 32 statements and 16 expressions. A standalone expression
never contains a statement, and a single name needs neither buffer.

We now start with empty buffers in both expression modes. Longer
expression lists grow their buffer as needed. Module and IPython parsing
keep their existing reservations.

Across 12 pairs of single-worker checks, total requested bytes fell from
412 MB to 396 MB, counting the full size of each reallocation. Peak live
heap was flat. At default parallelism, the peak RSS change on Sentry was
within noise. On discord.py, peak RSS rose 0.34% across 56 pairs, with a
95% interval from −0.11% to +0.55%.
2026-11-30 15:07:23 -05:00
Alex Waygood 1d54002049 [ty] Correct seven more rule descriptions (#31154) 2026-11-30 19:35:05 +00:00
Carl Meyer 7b66e47507 [ty] Allow factory_boy subclasses to redeclare Meta and Params (#30939)
Main reports `incompatible-attribute-override` on both `Meta`
declarations below. [factory_boy’s
metaclass](https://github.com/FactoryBoy/factory_boy/blob/3.3.3/factory/base.py#L71-L90)
removes `Meta` and `Params` before creating each factory, so there’s no
inherited configuration class to override.

```python
import factory

class Base(factory.Factory):
    class Meta:
        abstract = True

class Child(Base):
    class Meta:
        model = dict
```

ty now accepts both declarations and reports `missing-attribute` if you
try to access `Base.Meta`, which raises `AttributeError` at runtime.
Other nested classes still get the usual override checks.

This applies to nested class declarations when the metaclass is
`factory.base.FactoryMetaClass` or a subclass.

This parallels our existing special-casing of Django inner Meta classes.
`factory_boy` is a popular test-object-factory library used with Django,
and copied its inner-Meta configuration pattern.

Fixes astral-sh/ty#5123.
2026-11-30 10:05:01 -08:00
David Peter 99ab05df7e [ty] Fix stack overflow when checking generic return types with recursive aliases (#30934)
## Summary

This smaller example also crashes ty 0.0.110 (Python 3.12+).

```python
type A[T] = list[list[T]] | list[A[T]]

def g[T]() -> A[T]:
    return []

def f[U]() -> A[U]:
    return g()
```

At `return g()`, ty uses the expected return type `A[U]` to help infer
`T`. It first tries to rule out alternatives in the two unions that
can't overlap. One comparison pairs `list[list[T]]` from `A[T]` with
`list[A[U]]` from `A[U]`.

Because `list` is invariant, ty asks whether the element types `list[T]`
and `A[U]` can be equivalent. Expanding `A[U]` gives `list[list[U]] |
list[A[U]]`. For both alternatives to fit `list[T]`, the solver requires
`T` to equal both `list[U]` and `A[U]`.

Can those two requirements hold together? To find out, the solver
compares `list[U]` with `A[U]`. This repeats the previous comparison
with `U` in place of `T`. From here on, each check starts a new check of
exactly the same constraints.

```text
T = list[U]  and  T = A[U]
U = list[U]  and  U = A[U]
U = list[U]  and  U = A[U]
...
```

The solver only cached completed checks. Since each check waited for the
next one to finish, the cache stayed empty for those constraints and the
stack overflowed.

Fixes astral-sh/ty#5114.

## How the fix works

When the solver starts checking whether a set of constraints has a
solution, it records an in-progress entry (`None`) in the cache. If a
nested check reaches the same constraints with the same set of variables
it can infer, it provisionally assumes a solution exists. This breaks
the cycle and lets the solver check the remaining bounds.

An answer that depends on that assumption may be unsafe to reuse. For
example, suppose check `P` requires `Q` and one more condition, and `Q`
in turn requires `P`. The provisional success for `P` lets `Q` pass. If
the other condition then fails, a cached success for `Q` would be wrong.

To avoid this, the solver increments a counter each time it makes a
provisional assumption. If the counter changed during a check, the
solver removes that check's cache entry when it finishes.

## Test plan

The regression mdtest checks that `good` can return `g(x)` and that
`bad` gets an `invalid-explicit-return` diagnostic for `return g("s")`.
Verified that the mdtest overflows without the fix and passes with it.
The `ty_python_semantic` test suite and Clippy also passed locally.
2026-11-30 17:35:41 +01:00
Charlie MarshandCharlie Marsh 9c350fb69a [ty] Freeze Salsa inputs when updating a baseline (#31059)
## Summary

A one-shot `ty check` freezes frequently read inputs so Salsa can skip
tracking dependencies on them. Today, adding `--update-baseline` leaves
those inputs mutable, even though we write the baseline after checking
and never reload it.

We now freeze the same inputs for one-shot baseline updates. We still
read the existing baseline and match diagnostics against it. Watch mode,
fixes, and memory reports continue to use mutable inputs.

---------

Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
2026-11-30 16:05:25 +00:00
Alex Waygood 56ad10d1a2 [ty] Clarify the documentation for three removed rules (#31140) 2026-11-30 14:54:39 +00:00
Charlie Marsh 0a33669ea3 [ty] Avoid cloning the cache handle when loading a parsed module (#31008)
## Summary

Loading a parsed module takes two strong references. One keeps the
indexed AST alive. The other points to the cache slot that ty can clear
and repopulate. Each time we load or clone the AST handle, we also
increment the slot's reference count, even though ordinary callers only
need the AST, the file and the Python version.

We now store the file and Python version with the indexed AST. A loaded
handle owns just the AST. If a language server operation needs to clear
a closed file's cache slot on drop, its guard retains the slot. Other
handles can keep using their AST after the slot is cleared or the file
is reparsed. On x86-64, this shrinks `ParsedModuleRef` from 32 to 8
bytes and adds 16 bytes per shared indexed AST.

The table compares release builds with the locked Salsa dependency on
two 32-vCPU AMD EPYC hosts and an Apple M5 Max.

| Project | Platform | Pairs | Base (ms) | PR (ms) | Wall time [95%
interval] | CPU time | Peak RSS |
|---|---|---:|---:|---:|---:|---:|---:|
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| Linux | 384 | 2049.5 | 2026.3 | −1.03% [−1.85, −0.52] | −0.87% |
−0.07% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| macOS | 384 | 1232.6 | 1225.1 | −0.46% [−1.20, +0.37] | −0.38% |
−0.13% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| Linux | 256 | 1281.0 | 1274.4 | −0.52% [−1.08, +0.16] | −0.11% |
+0.07% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| macOS | 256 | 611.5 | 611.9 | −0.83% [−1.27, +0.07] | −0.94% | −0.45%
|
2026-11-30 09:10:17 -05:00
Micha Reiser 9fcca12350 [ty] Speed up exit when a pipe closes during ty check (#31141)
## Summary

Today, piping `ty check` into `head` can make ty drop its entire Salsa
cache when the pipe closes. This PR skips that drop before propagating
errors from the main loop or memory report.

On PyTorch, the median time from closing the pipe after the first
diagnostic to process exit fell from 1.09 s to 216 ms over six runs per
version.

The ty CLI tests passed, and I verified the exit codes for broken pipes
and other write errors.
2026-11-30 13:47:41 +00:00
David Peter 0e78666eb1 [ty] Preserve Never field types in generated dataclass methods (#31135)
## Summary

ty accepted `Impossible(value=1)` for a dataclass with a required
`value: Never` field, even though it inferred `Never` when reading the
field.

Looking up `__set__` on `Never` yields `Never`. Since ty treats `Never`
as callable with arbitrary arguments, it inferred `Unknown` for the
setter's value parameter. Here, we simply extend a special-case that was
previously only active for dynamic types. This is something that's very
common in ty: almost all special-cases for dynamic types apply to
`Never` as well.

fixes astral-sh/ty#5140
2026-11-30 14:38:12 +01:00
David Peter c36f4665cb [ty] Preserve attrs field converters when a validator is present (#31131)
## Summary

attrs `field()` is overloaded. There are (valid) `field` calls that can
lead to ambiguous overloads. In the example in astral-sh/ty#5134, this
is caused by passing in a converter which takes an unspecialized
`Attribute` argument (i.e. `Attribute[Unknown]`). With the change here,
instead of "giving up", we combine/merge the result of ambiguous
`field()` calls by merging their `Field` instances if the agree in
metadata (`kw_only`, `init`, `converter`, ...).

I believe I've seen cases of this in other dataclass-transformer
libraries as well, which is why I added a test in `dataclass_transform`
as well.

Closes astral-sh/ty#5134
2026-11-30 13:53:55 +01:00
Alex Waygood cb17cd8fd4 [ty] Fix a panic on recursive enum value annotations (#30765) 2026-11-30 12:19:25 +00:00
Charlie Marsh 4bde5e2dc1 Revert file data reuse in the concise renderer (#31133)
## Summary

This reverts #31085. The cache helped on the PyTorch benchmark, where we
rendered many consecutive diagnostics for the same file. As [Micha
pointed
out](https://github.com/astral-sh/ruff/pull/31085#issuecomment-7271420043),
when each file has just one diagnostic, we populate the cache for every
file and never reuse it.
2026-11-30 11:59:24 +00:00
Charlie Marsh 97bcb119dd [ty] Update benchmark checker pins (#31128) 2026-11-30 06:44:11 -05:00
Shehryar Hassan cdceabe630 [pep8-naming] Allow trailing underscores in class names (N801) (#31130)
## Summary

Fixes #30230.

`non_camel_case_class_name` in `non_camel_case_class_name.rs` only
stripped leading underscores (`trim_start_matches('_')`), so valid PEP 8
class names with trailing underscores like `Fine_` were still flagged.

Changed it to `trim_matches('_')` to strip both leading and trailing
underscores, matching upstream `pep8-naming` (while still flagging
internal underscores like `Bad_Class_`, lowercase names like `bad_`, and
underscore-only names like `_` and `__`). Added test cases to `N801.py`
and updated the snapshot.

Ran `cargo test -p ruff_linter`, `cargo clippy`, and `cargo fmt --check`
locally.

AI disclosure: Used AI to help check edge cases and upstream behavior; I
reviewed the diff and ran the checks myself.
2026-11-30 11:59:20 +01:00
Michał FoxandMicha Reiser e0365b5daa [isort] Ignore trailing comma when splitting aliased imports (I001) (#29693)
## Summary

with `combine-as-imports = false` (the default) an import like `from
aws_cdk import (NestedStack, aws_ecr as ecr, ...,)` is split into one
statement per aliased member, and each of them inherited the original
trailing comma, so every one was expanded into its own parenthesized
block. as suggested by @MichaReiser, the trailing comma is now ignored
when one statement is split into several, so each lands on one line like
isort does by default. a single aliased import or an import without
aliases still keeps its magic trailing comma.

Closes #16399

## Test Plan

added `trailing_comma_as_imports.py` with the example from the issue
plus two cases where the trailing comma should still be respected, and a
snapshot for it. the existing isort snapshots are unchanged.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
2026-11-30 10:58:47 +00:00
DrSkyleandMicha Reiser c1dd0145b1 fix(pylint): flag from imports that resolve to the current module (PLW0406) (#31034)
## Summary

PLW0406 caught self-imports like `from . import module` but missed `from
.module import foo` inside `module.py`. The rule now reports the whole
statement when the resolved source is the current module. When importing
the current module from its parent package, it still highlights only the
matching alias.

Added fixture and snapshot coverage for absolute and relative imports,
multiple names, star imports, and imports from the parent package that
should not be flagged.


Closes https://github.com/astral-sh/ruff/issues/30229

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
2026-11-30 10:34:40 +00:00
vivodi 4eb7f46092 Remove Markdown support instructions for ruff-pre-commit (#30979)
## Summary

<!-- What's the purpose of the change? What does it do, and why? -->
Following the changes in
https://github.com/astral-sh/ruff-pre-commit/pull/159, Markdown support
when running Ruff via
[`ruff-pre-commit`](https://github.com/astral-sh/ruff-pre-commit) now
works out of the box, with no manual configuration required.
2026-11-30 10:24:05 +01:00
Chua Yu Jien bdbb14eeda Make PTH208 and RUF056 documentation examples runnable (#31039)
Part of [Issue #18972](https://github.com/astral-sh/ruff/issues/18972)
2026-11-30 10:22:41 +01:00
zibuyu e960604af0 [ruff] Skip assignments across with blocks in RUF070 (#31054)
The original code exits the with block, closing the file before yielding
the data it has already read to the caller.
Fixes #25653
2026-11-30 10:19:38 +01:00