mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-22 09:50:54 +08:00
main
3489
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9ca2a80e78 |
[ty] Avoid repeated path scans when building solver cache keys (#30650)
## Summary When ty checks the call to `super().__init__` in Bokeh’s `HatchPatternType`, it solves constraints on the type variables in the overloads of `Either.__init__`. At each node of the constraint diagram, the solver builds a cache key from the assignments that could affect its solutions. It can scan the path several times to find those assignments even when every type variable is already relevant. [Bokeh call site](https://github.com/bokeh/bokeh/blob/378373772846cdfedc1c641ce9219dcbc34b6b9c/src/bokeh/core/property/visual.py#L137-L147) · [Reproducer](https://github.com/astral-sh/ty/issues/5063#bokeh-receiver-specialization) We now stop expanding the set of relevant variables when it contains every type variable in the constraint storage. Each constraint has a subject variable, so every positive and negative assignment on that path belongs in the key. We reserve space for the assignments up front and sort them by local constraint ID, which gives each set a canonical order within the walk. Cold checks of Bokeh’s `src` and `tools/release` (492 files) used 3.35–3.38% fewer instructions in opposite orders, with a 0.018% same-binary control spread. Both builds produced the same 686 diagnostics. On `src/bokeh/core/property/visual.py` alone, the reduction was 13.97–13.98%. Applying this patch on top of the early exit in #30653 reduced the remaining instruction count on `visual.py` by 33.95–34.13%. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/478a66e6de8adf9fa740cd8af0d380e0c2e4db6a) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,174,108,256.5 | 3,173,516,722 | -0.02% | -0.03% to 0.00% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,235,225,120 | 8,242,644,305.5 | +0.09% | +0.05% to +0.13% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,254,140,465 | 159,217,941,862.5 | -0.02% | -0.04% to -0.01% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,861,761,369.5 | 1,862,681,165 | +0.05% | +0.03% to +0.07% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,946,829,713 | 1,943,623,224 | -0.16% | -0.22% to -0.11% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 28,855,744,409 | 28,817,081,431 | -0.13% | -0.14% to -0.13% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,975,665,415.5 | 2,977,886,827.5 | +0.07% | -0.08% to +0.23% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,959,292,278 | 4,957,042,736 | -0.05% | -0.10% to +0.01% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 96,677,077,177.5 | 96,597,935,276 | -0.08% | -0.15% to -0.01% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,684,159,398.5 | 1,682,827,570.5 | -0.08% | -0.21% to +0.05% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,498,640,458 | 8,484,590,326 | -0.17% | -0.34% to +0.01% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 3,008,414,987 | 3,008,383,732 | 0.00% | -0.01% to +0.01% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,538,629,407 | 21,493,439,331 | -0.21% | -0.23% to -0.19% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,721,291,053.5 | 2,722,920,861 | +0.06% | -0.06% to +0.18% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,909,811,424 | 13,898,353,119.5 | -0.08% | -0.18% to +0.02% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,205,015,573 | 46,157,556,697.5 | -0.10% | -0.14% to -0.06% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 16,017,127,816.5 | 16,015,781,142 | -0.01% | -0.02% to 0.00% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,821,640,105.5 | 8,817,780,883.5 | -0.04% | -0.16% to +0.07% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,175,140,184.5 | 4,176,532,153 | +0.03% | -0.04% to +0.10% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,440,574,326 | 14,448,686,368.5 | +0.06% | 0.00% to +0.11% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,024,346,791.5 | 3,026,562,737.5 | +0.07% | -0.01% to +0.16% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,823,926,685.5 | 4,819,110,155.5 | -0.10% | -0.12% to -0.08% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 34,971,843,985.5 | 34,929,440,768 | -0.12% | -0.15% to -0.10% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 15,750,955,779.5 | 15,754,926,138.5 | +0.03% | -0.01% to +0.06% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,073,082,917 | 13,064,695,805.5 | -0.06% | -0.13% to 0.00% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 66,899,541,927.5 | 66,888,821,170 | -0.02% | -0.02% to -0.01% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,979,728,756 | 8,980,454,138.5 | +0.01% | -0.14% to +0.16% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 102,028,019,170 | 102,068,912,921 | +0.04% | -0.07% to +0.15% | |
||
|
|
11e94e2828 |
[ty] Skip incompatible TypedDict union members when inferring dictionary literals (#30641)
## Summary
When ty checks `{"type": "union", "choices": [{"type": "int"}, {"type":
"float"}]}` against Pydantic Core's `CoreSchema`, it tries all 59
`TypedDict`s. It infers `choices` even for schemas that require a
different `type` tag.
We now skip a candidate before inferring the values if a required key is
missing or a required string tag conflicts with the literal. We check
dictionaries whose keys are all string literals, using the last value
for repeated keys. A computed key or a `**` unpack could supply a
missing field or overwrite a tag.
Cold checks used 12.69–12.91% fewer instructions on the Pydantic Core
project (134 files) and 62.15–62.17% fewer on `tests/test_typing.py`
alone. The OpenAI Agents SDK's `tests/extensions/memory/` directory used
10.56–10.65% fewer. [Pydantic
Core](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3/pydantic-core)
· [Agents SDK memory
tests](https://github.com/openai/openai-agents-python/tree/6c4e4a29cd08eef454db6980d74da6afc8939d24/tests/extensions/memory)
## Pinned projects
The Pydantic row checks the 55 files in the `pydantic/` package. In a
separate serial repeat, both pytest pairs used 0.16% fewer instructions,
within the 0.35% variation between consecutive checks with the same
binary.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/1115003f608598a821d1aa7efeb0fefc1e7acd73)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
(inconclusive) | 3,180,362,811 | 3,173,024,995.5 | -0.23% | -0.43% to
-0.03% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
(inconclusive) | 8,250,316,762.5 | 8,256,364,824.5 | +0.07% | -0.07% to
+0.22% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 159,284,924,031 | 159,224,734,983.5 | -0.04% | -0.04% to -0.03% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
(inconclusive) | 1,857,160,007.5 | 1,856,125,205 | -0.05% | -0.46% to
+0.35% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
(inconclusive) | 1,946,982,759 | 1,942,539,120 | -0.23% | -0.35% to
-0.11% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
(inconclusive) | 28,824,498,732.5 | 28,796,162,668 | -0.10% | -0.11% to
-0.09% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
(inconclusive) | 2,975,041,644.5 | 2,970,777,113.5 | -0.14% | -0.27% to
-0.02% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
(inconclusive) | 4,958,548,140.5 | 4,958,263,017.5 | -0.01% | -0.01% to
0.00% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 96,649,807,586.5 | 96,600,313,311.5 | -0.05% | -0.06% to -0.05% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
(inconclusive) | 1,682,000,652.5 | 1,683,197,725 | +0.07% | +0.06% to
+0.08% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 8,554,986,848 | 8,557,857,817 | +0.03% | -0.03% to
+0.10% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
(inconclusive) | 3,007,194,779 | 3,005,986,069.5 | -0.04% | -0.06% to
-0.02% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
(inconclusive) | 21,539,239,584.5 | 21,520,156,231 | -0.09% | -0.18% to
0.00% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
(inconclusive) | 2,727,630,208.5 | 2,722,386,665.5 | -0.19% | -0.43% to
+0.05% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
(inconclusive) | 13,908,902,990 | 13,908,079,615.5 | -0.01% | -0.12% to
+0.11% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
(inconclusive) | 46,169,520,073.5 | 46,165,531,525.5 | -0.01% | -0.05%
to +0.03% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
(inconclusive) | 16,020,695,437 | 15,997,906,899 | -0.14% | -0.19% to
-0.09% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 8,811,494,792 | 8,816,893,703 | +0.06% | +0.04% to +0.08% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
(inconclusive) | 4,174,314,733 | 4,174,752,847.5 | +0.01% | -0.07% to
+0.09% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 14,459,679,374 | 14,446,949,627 | -0.09% | -0.12% to -0.05% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
(inconclusive) | 3,027,633,125.5 | 3,026,012,940 | -0.05% | -0.17% to
+0.06% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
(inconclusive) | 4,823,887,962 | 4,822,076,737 | -0.04% | -0.14% to
+0.06% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 34,992,809,088.5 | 34,952,789,155.5 | -0.11% | -0.16% to -0.07% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 15,759,940,126.5 | 15,742,537,811.5 | -0.11% | -0.12% to -0.10% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 13,066,992,993.5 | 13,049,033,053.5 | -0.14% | -0.14% to -0.14% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
(inconclusive) | 66,866,675,196.5 | 66,857,495,258.5 | -0.01% | -0.05%
to +0.03% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
(inconclusive) | 8,977,022,049.5 | 8,975,774,708.5 | -0.01% | -0.04% to
+0.02% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
(inconclusive) | 102,128,236,207 | 102,066,149,367.5 | -0.06% | -0.13%
to 0.00% |
|
||
|
|
f31dd86f22 |
[ty] Reuse mapping value types when unpacking keyword arguments (#30638)
## Summary When we check `f(**options)`, we infer the type of `options["timeout"]` once per overload that accepts `timeout`. We now cache that type by mapping type and key. If `__getitem__` recursively unpacks the same mapping, we bypass the cache so return type inference can resolve the cycle. In Ansible’s AWS helper, 53,104 requests needed only 20 computations. Cold checks used 17.64–17.71% fewer instructions for the collection’s `plugins/module_utils` with `boto3-stubs` and 10.25–10.39% fewer for Remotion’s Lambda Python package. [Ansible call site](https://github.com/ansible-collections/amazon.aws/blob/49e74a059c3fb2f1edd4f6a40105e7e53400818f/plugins/module_utils/botocore.py#L181-L187), [Remotion call site](https://github.com/remotion-dev/remotion/blob/2c93495f062a688e9ccb6ee90b6d57560080571e/packages/lambda-python/remotion_lambda/remotionclient.py#L242-L267) | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/7b855a6f694e687f7902b27842bccc2fb3cfbef5) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,171,801,466 | 3,169,035,907.5 | -0.09% | -0.10% to -0.08% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,250,616,901.5 | 8,177,924,067 | -0.88% | -1.03% to -0.73% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,266,177,927 | 159,028,883,587.5 | -0.15% | -0.15% to -0.15% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,864,065,239 | 1,855,375,386.5 | -0.47% | -0.49% to -0.44% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,943,162,825.5 | 1,938,087,991 | -0.26% | -0.35% to -0.17% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 28,826,780,884 | 28,715,893,158.5 | -0.38% | -0.41% to -0.36% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,970,521,765 | 2,974,646,132 | +0.14% | +0.08% to +0.20% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,957,873,188 | 4,951,763,267 | -0.12% | -0.18% to -0.07% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 96,625,488,028 | 96,398,599,290.5 | -0.23% | -0.25% to -0.22% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,680,826,173 | 1,679,516,159 | -0.08% | -0.10% to -0.06% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,486,218,999 | 8,490,301,469 | +0.05% | +0.03% to +0.06% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,008,918,366 | 2,998,116,989 | -0.36% | -0.44% to -0.28% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,546,418,242 | 21,472,480,386 | -0.34% | -0.66% to -0.03% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,722,081,999 | 2,718,832,889.5 | -0.12% | -0.19% to -0.05% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 13,899,250,351 | 13,826,686,370.5 | -0.52% | -0.54% to -0.50% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,173,892,849.5 | 46,042,223,842.5 | -0.29% | -0.32% to -0.25% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 16,012,979,988.5 | 15,976,893,887 | -0.23% | -0.23% to -0.22% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,811,149,334.5 | 8,789,611,084 | -0.24% | -0.27% to -0.22% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,173,979,600.5 | 4,161,474,785 | -0.30% | -0.31% to -0.29% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,451,498,108 | 14,390,757,714 | -0.42% | -0.43% to -0.41% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,024,807,473.5 | 3,011,850,356 | -0.43% | -0.45% to -0.41% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,824,352,276 | 4,786,331,231 | -0.79% | -0.79% to -0.78% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 34,989,387,306.5 | 34,844,208,801 | -0.41% | -0.42% to -0.41% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 15,751,466,639 | 15,718,820,318 | -0.21% | -0.21% to -0.20% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,065,115,493.5 | 13,057,222,765 | -0.06% | -0.08% to -0.04% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 66,934,132,757 | 66,184,416,440 | -1.12% | -1.19% to -1.05% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,982,113,758 | 8,952,424,478.5 | -0.33% | -0.34% to -0.32% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 102,066,588,951 | 100,473,574,916.5 | -1.56% | -1.60% to -1.52% | |
||
|
|
05773e0aaa |
[ty] Stop searching for overlapping invariant arguments after finding a valid solution (#30653)
## Summary Setting `T = Literal["a"]` and `U = Literal["b"]` proves that `list[T | U]` and `list[Literal["a", "b"]]` can overlap. Today, ty keeps trying other ways to split the literals between `T` and `U`, which can exhaust the search budget for larger unions. When checking invariant arguments for overlap, we now stop at the first candidate that satisfies the type variables’ bounds and constraints. If the solver later rejects it, we retry the full search. On the revision linked below, cold checks of Bokeh’s `src` and `tools/release` used 19.4% fewer instructions. Checking `visual.py` alone used 78.7% fewer instructions, with median peak RSS rising from 112 to 121 MiB. [Bokeh call site](https://github.com/bokeh/bokeh/blob/378373772846cdfedc1c641ce9219dcbc34b6b9c/src/bokeh/core/property/visual.py#L135-L147), [reproducer](https://github.com/astral-sh/ty/issues/5063#bokeh-receiver-specialization) | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/407e15c7db7224dd2ba3fee2a334b9ad513187b9) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,172,474,934.5 | 3,175,542,480 | +0.10% | +0.06% to +0.14% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,255,868,023.5 | 8,241,907,660.5 | -0.17% | -0.20% to -0.14% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,246,040,277.5 | 159,322,153,893 | +0.05% | +0.04% to +0.05% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,861,066,525.5 | 1,857,096,534.5 | -0.21% | -0.42% to 0.00% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,945,400,625.5 | 1,946,857,804 | +0.07% | +0.03% to +0.12% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 28,828,777,770.5 | 28,847,158,758 | +0.06% | -0.03% to +0.16% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,968,570,115 | 2,966,260,796 | -0.08% | -0.24% to +0.08% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,961,546,853 | 4,961,115,537 | -0.01% | -0.04% to +0.02% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 96,720,429,485 | 96,682,995,103 | -0.04% | -0.10% to +0.02% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,683,113,305.5 | 1,684,259,551.5 | +0.07% | +0.03% to +0.10% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,470,780,308.5 | 8,481,660,788.5 | +0.13% | -0.11% to +0.37% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 3,016,021,500 | 3,010,738,390.5 | -0.17% | -0.44% to +0.09% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,518,447,707 | 21,538,763,198.5 | +0.09% | +0.06% to +0.13% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,718,791,017 | 2,721,916,861.5 | +0.12% | -0.14% to +0.37% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,904,812,552 | 13,918,802,558 | +0.10% | -0.07% to +0.27% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,181,548,169.5 | 46,165,091,541 | -0.04% | -0.08% to +0.01% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 16,018,628,923 | 16,019,208,155 | 0.00% | -0.01% to +0.02% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,819,089,975 | 8,820,455,699 | +0.02% | -0.04% to +0.07% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,177,902,998.5 | 4,174,650,974 | -0.08% | -0.14% to -0.02% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,453,096,661.5 | 14,464,997,631 | +0.08% | +0.02% to +0.14% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,024,539,413.5 | 3,026,746,086 | +0.07% | +0.07% to +0.08% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,823,783,670 | 4,821,754,930 | -0.04% | -0.12% to +0.03% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 34,961,840,699 | 34,971,632,672.5 | +0.03% | +0.02% to +0.04% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 15,749,998,166.5 | 15,757,142,806.5 | +0.05% | +0.04% to +0.05% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,064,499,018 | 13,063,125,433.5 | -0.01% | -0.07% to +0.05% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 66,883,118,669 | 66,830,667,139.5 | -0.08% | -0.08% to -0.08% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,981,963,751 | 8,979,675,403 | -0.03% | -0.04% to -0.01% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 102,022,093,779.5 | 102,183,015,680 | +0.16% | +0.10% to +0.22% | |
||
|
|
b09f331a3a |
[ty] Reuse overload prefix checks across calls (#30640)
## Summary When an argument of type `Any` matches several overloads, ty checks whether the first overload, then the first two, and so on, accept every materialization of the arguments. Each step builds a union of parameter types. Calls to the same overloaded function can repeat the entire search with identical types. We now reuse the number of overloads to keep when the inferable type variables and the argument and parameter types at the distinguishing positions agree. We still compare the remaining return types at each call site and evaluate the search directly during cycle recovery. ## Performance After a full check of scikit-learn, the cache holds 4.01 MiB of keys, results and Salsa metadata. With one worker, total live Salsa storage grows 0.97% with the frozen inputs used by the CLI and falls 2.67% with mutable inputs. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/ce4906c7203f761ff6b2b2748b3cbf1af653388e) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,172,849,958.5 | 3,171,504,084 | -0.04% | -0.06% to -0.03% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,244,551,270 | 8,225,108,318.5 | -0.24% | -0.26% to -0.21% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,255,076,114 | 159,160,797,237 | -0.06% | -0.07% to -0.05% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,860,603,867.5 | 1,858,126,810 | -0.13% | -0.21% to -0.06% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,946,524,045.5 | 1,943,888,989.5 | -0.14% | -0.14% to -0.13% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 28,831,258,280.5 | 28,495,153,924 | -1.17% | -1.26% to -1.08% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,971,313,111 | 2,972,442,653 | +0.04% | -0.26% to +0.33% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,957,712,369.5 | 4,952,626,259.5 | -0.10% | -0.11% to -0.09% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 96,639,048,118.5 | 96,414,268,431.5 | -0.23% | -0.26% to -0.21% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,683,810,371.5 | 1,682,014,111 | -0.11% | -0.13% to -0.08% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,497,337,652.5 | 8,480,204,308.5 | -0.20% | -0.32% to -0.09% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 3,008,218,552 | 3,004,472,580.5 | -0.12% | -0.22% to -0.03% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,521,362,036.5 | 21,427,512,841 | -0.44% | -0.48% to -0.39% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,723,800,499.5 | 2,717,501,353.5 | -0.23% | -0.37% to -0.09% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 13,912,015,847 | 13,883,110,045 | -0.21% | -0.28% to -0.13% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,177,370,870 | 45,967,496,305.5 | -0.45% | -0.45% to -0.45% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 16,023,139,660 | 16,002,107,945.5 | -0.13% | -0.24% to -0.03% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,814,471,520.5 | 8,798,972,122.5 | -0.18% | -0.27% to -0.08% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,175,149,063.5 | 4,172,710,283.5 | -0.06% | -0.15% to +0.04% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,442,791,334.5 | 14,401,352,824 | -0.29% | -0.32% to -0.25% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,026,052,345 | 3,023,319,766 | -0.09% | -0.10% to -0.08% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,823,425,865.5 | 4,812,542,246 | -0.23% | -0.29% to -0.16% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 34,967,356,287.5 | 33,935,527,972 | -2.95% | -2.98% to -2.93% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 15,760,776,050.5 | 15,624,434,259.5 | -0.87% | -0.87% to -0.86% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,064,494,398 | 13,039,730,470.5 | -0.19% | -0.19% to -0.19% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 66,902,103,018 | 62,012,792,620 | -7.31% | -7.39% to -7.22% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,974,801,335.5 | 8,962,767,833.5 | -0.13% | -0.17% to -0.10% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 102,173,739,178.5 | 101,044,134,037.5 | -1.11% | -1.21% to -1.01% | |
||
|
|
be0f014c76 |
[ty] Index enum members by name (#30634)
## Summary ty looks up each enum member by name when checking its value against the enum constructor. Each lookup scans the members from the start. For LIEF's x86 `OPCODE` enum, checking all 22,296 declarations takes about 249 million name comparisons. [Source](https://github.com/lief-project/LIEF/blob/d05b3499b6934137e917c009a4df0a9dc8cb11c5/api/python/lief/assembly/x86/__init__.pyi#L8) We now store canonical members in an `FxOrderMap`, which supports direct lookup by name and iteration in declaration order. Each nonempty enum retains one extra allocation. On x86-64, a four-member enum requests 160 extra bytes across its Salsa slot and member buffers. A cold `ty check` of the full Python package used 64.54–64.55% fewer instructions on LIEF 1.0.0 and 17.06–17.17% fewer on Flet 0.28.3 across two opposite-order Cachegrind pairs. The largest same-binary difference was 0.13%. Diagnostics and exit statuses matched on both packages. [LIEF 1.0.0](https://pypi.org/project/lief/1.0.0/) · [Flet 0.28.3](https://pypi.org/project/flet/0.28.3/) In follow-up checks of the two largest increases in the table, isort used more instructions in eight of ten pairs (median +0.05%, range −0.04% to +0.25%). The two SQLAlchemy pairs changed by +0.19% and −0.03%. Same-binary differences reached 0.24% on isort and 0.16% on SQLAlchemy. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/ded86a3b07accc6195d55be0dff33173f14579e7) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,173,058,915 | 3,176,939,064 | +0.12% | -0.08% to +0.33% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,256,334,854.5 | 8,257,214,579.5 | +0.01% | -0.18% to +0.20% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,282,675,978.5 | 159,327,719,702 | +0.03% | +0.02% to +0.03% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,856,784,451 | 1,862,613,044.5 | +0.31% | +0.20% to +0.43% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,948,128,539 | 1,945,455,202.5 | -0.14% | -0.15% to -0.12% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 28,842,034,734 | 28,851,020,348 | +0.03% | 0.00% to +0.06% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,972,982,324.5 | 2,967,221,342 | -0.19% | -0.23% to -0.16% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,961,026,239.5 | 4,962,547,009 | +0.03% | +0.02% to +0.04% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 96,640,417,792.5 | 96,758,087,402 | +0.12% | -0.06% to +0.31% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,679,905,481 | 1,682,133,482 | +0.13% | +0.11% to +0.15% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,527,699,469 | 8,501,482,525.5 | -0.31% | -0.56% to -0.05% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 3,010,145,352 | 3,010,629,709 | +0.02% | -0.07% to +0.11% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,500,556,547.5 | 21,530,521,895 | +0.14% | +0.08% to +0.19% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,731,160,742.5 | 2,724,601,366 | -0.24% | -0.51% to +0.03% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,937,743,513.5 | 13,925,737,082.5 | -0.09% | -0.26% to +0.09% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,183,130,722 | 46,204,976,066.5 | +0.05% | +0.02% to +0.07% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 16,022,228,521 | 16,024,488,542.5 | +0.01% | -0.03% to +0.06% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,823,435,940.5 | 8,818,771,534 | -0.05% | -0.22% to +0.12% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,175,773,101.5 | 4,179,487,683 | +0.09% | +0.06% to +0.12% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,453,090,688 | 14,453,862,256 | +0.01% | -0.01% to +0.02% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,026,266,810.5 | 3,027,413,278.5 | +0.04% | -0.03% to +0.11% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,822,792,460 | 4,828,216,130.5 | +0.11% | +0.04% to +0.18% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 34,981,484,267 | 34,998,787,438 | +0.05% | +0.04% to +0.06% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 15,758,285,925 | 15,764,681,471.5 | +0.04% | +0.03% to +0.05% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,074,313,054 | 13,077,168,632 | +0.02% | -0.01% to +0.05% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 66,922,241,745.5 | 66,945,485,873.5 | +0.03% | +0.02% to +0.05% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,980,454,833.5 | 8,984,931,569 | +0.05% | -0.04% to +0.14% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 102,131,622,715 | 102,217,415,495 | +0.08% | -0.03% to +0.19% | |
||
|
|
770b239784 |
[ty] Skip union comparisons between class literals with the same truthiness guard (#30636)
## Summary yt-dlp’s generated extractor registry holds 1,754 distinct classes. When the lookup rules out falsy values, ty intersects each class literal with `~AlwaysFalsy`. Rebuilding the union then checks both directions of redundancy for over 1.5 million pairs of intersections. [Extractor lookup](https://github.com/yt-dlp/yt-dlp/blob/c91f8de0bfb3577894abad716eaaa01659e6bd14/yt_dlp/extractor/extractors.py#L39-L43) We now skip the redundancy checks for distinct class literals with the same truthiness guard. The intersection builder reduces an arm to `Never` if the guard rules it out. For two guarded arms, the redundancy check requires one class literal to be a subtype of the other. Distinct literals identify different objects, even when one class inherits from the other. Checking `yt_dlp/extractor/extractors.py` used 92.62% fewer instructions in both orders. The number of cached redundancy results fell from 3,092,365 to 14,095. A cold check of all 1,044 Python files in the release wheel used 27.42% fewer instructions in both orders, with identical diagnostics. [yt-dlp 2026.10.26](https://pypi.org/project/yt-dlp/2026.10.26/#files) On a second host, the same binaries used 0.10–0.32% more instructions on discord.py, with a 0.19% spread across three runs of the base binary. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a866aff503fd777156c1ae4eae318a3795fa09ec) | [PR instructions](https://github.com/astral-sh/ruff/commit/58e587884ad41d3cf64035b05a3279126fb65c5a) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,171,169,060.5 | 3,170,645,867.5 | -0.02% | -0.03% to 0.00% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,230,879,286.5 | 8,245,219,588.5 | +0.17% | +0.16% to +0.18% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) (inconclusive) | 159,250,393,000 | 159,270,973,642.5 | +0.01% | +0.01% to +0.02% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,862,118,653.5 | 1,861,863,263.5 | -0.01% | -0.08% to +0.05% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,944,254,302.5 | 1,944,729,805.5 | +0.02% | -0.08% to +0.13% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 28,827,590,327.5 | 28,849,467,071 | +0.08% | -0.03% to +0.18% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,970,066,476.5 | 2,972,192,091.5 | +0.07% | -0.23% to +0.37% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,959,079,509.5 | 4,957,792,398 | -0.03% | -0.03% to -0.02% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 96,650,644,294.5 | 96,765,513,628 | +0.12% | -0.01% to +0.25% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,683,914,486.5 | 1,680,731,882.5 | -0.19% | -0.34% to -0.03% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,483,984,688.5 | 8,487,892,264 | +0.05% | +0.01% to +0.09% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 3,007,532,626 | 3,008,548,271.5 | +0.03% | +0.02% to +0.05% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,535,135,870.5 | 21,483,318,795.5 | -0.24% | -0.26% to -0.22% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,727,362,038 | 2,724,467,877 | -0.11% | -0.25% to +0.04% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,913,117,272 | 13,892,237,683 | -0.15% | -0.25% to -0.05% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,189,579,595.5 | 46,161,453,151.5 | -0.06% | -0.06% to -0.06% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 16,012,846,939.5 | 16,020,414,115.5 | +0.05% | -0.02% to +0.12% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,817,598,637.5 | 8,814,489,978.5 | -0.04% | -0.08% to +0.01% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,174,975,233 | 4,176,083,517.5 | +0.03% | -0.03% to +0.09% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,458,295,336.5 | 14,440,776,369 | -0.12% | -0.15% to -0.09% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,024,794,475 | 3,025,459,826 | +0.02% | -0.03% to +0.08% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,824,373,538.5 | 4,821,913,516.5 | -0.05% | -0.09% to -0.01% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 34,981,569,712.5 | 34,962,278,587.5 | -0.06% | -0.07% to -0.04% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 15,757,347,494.5 | 15,753,869,450.5 | -0.02% | -0.03% to -0.02% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,068,670,177.5 | 13,065,655,815 | -0.02% | -0.06% to +0.01% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 66,865,955,659.5 | 66,906,377,321 | +0.06% | -0.01% to +0.13% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,973,859,828 | 8,966,220,889.5 | -0.09% | -0.14% to -0.03% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 102,145,113,244.5 | 102,118,338,924 | -0.03% | -0.08% to +0.02% | |
||
|
|
36f64044cb |
[ty] Forward the suffix of a positional unpack to a ParamSpec (#30594)
When an unpacked tuple supplies both a wrapper’s callback and arguments
for that callback, main loses track of which values the wrapper
forwards:
```py
from collections.abc import Callable
def invoke[**P](callback: Callable[P, None], /, *args: P.args, **kwargs: P.kwargs) -> None:
callback(*args, **kwargs)
def write(x: int, y: str) -> None: ...
invoke(*(write, 1, "ok"))
invoke(*(write, 1), "ok")
```
Both calls invoke `write(1, "ok")`. On main, ty checks the first as
`write()` and reports missing arguments. In the second, it passes
`write` itself as the first argument to the callback and reports too
many arguments.
This change removes the elements that bind to the wrapper’s parameters
before checking the callback. Both calls now pass. If the final argument
is `2`, ty points to the offending argument and the declaration of `y:
str`. The same forwarded arguments provide type context for expressions
such as list literals.
We slice each tuple in a union separately so overload resolution can
distinguish the alternatives. For a variable-length tuple, we can
forward the rest precisely when the wrapper consumes elements from its
fixed prefix.
This complements #30566, which uses the forwarded arguments to infer a
generic callback’s return type.
## Ecosystem report
Across 166 projects, the only stable change at `d013aae8ad` removes a
false positive in NumPy’s threaded test helper. The helper passes the
callback and its worker index together in `executor.submit(*arg)`. Ty
now checks the index against the callback’s parameters. [Full ecosystem
report](https://github.com/astral-sh/ruff/pull/30594#issuecomment-7024429167)
|
||
|
|
e905eb561c |
[ty] Fix a panic when reporting invalid type parameter order in unpacked class bases (#30630)
## Summary Today, ty panics on `class C(*(int, Generic[T, U]))` when `T` has a default and `U` is required. To locate the error, ty looks for the second base in the class header. The header contains a single starred expression that expands to two bases. This PR changes the diagnostic to use the source expression ty recorded for each base during expansion, following #24695 and #24699. The diagnostic now underlines `T, U` and reports that a required type parameter cannot follow one with a default. Added an mdtest that checks the diagnostic on the unpacked generic base. |
||
|
|
d8c6e237e7 |
[ty] Split mismatched-type-name by type constructor (#29957)
## Summary
This PR splits `mismatched-type-name` into eight independently
configurable warnings for `NewType`, functional enums, `TypeVar`,
`ParamSpec`, `TypeVarTuple`, `namedtuple`/`NamedTuple`, `TypedDict`, and
`TypeAliasType`.
~~This PR is actually quite a bit less breaking for users than other
rule splits we've done over the last few days. Because
`mismatched-type-name` is no longer the canonical name for _any_ rule on
this branch, we're able to make it a deprecated alias for _all_ the new
rules, meaning that it will continue to work on the CLI, in ty
configuration files, and ty suppression comments (we'll just emit a
warning diagnostic telling users to upgrade their configuration
file/suppression comment).~~
~~A more specific rule takes precedence over the deprecated name if both
are given within the same configuration table. On the command line, the
last matching flag wins (e.g. `--error=mismatched-enum-name
--ignore=mismatched-type-name` will suppress diagnostics for mismatched
enum names).~~
(After review from @MichaReiser, I backed out these changes. It's now a
somewhat breaking change, because the rule is now marked as "removed"
rather than "deprecated".)
As well as splitting the rule into eight separate rules, it also cleans
up our error recovery for several of these type factories. For example,
in the following snippet, we fail to recognize `T` as a `TypeVar` due to
bad error recovery from the non-literal name. But we don't really need a
nonliteral name in this case to determine that it's a validly
constructed TypeVar. It's probably a mistake, but there's no _soundness_
issue here:
```py
from typing import TypeVar
def f(x: str):
# main emits an error: `invalid-typevar`
# this PR emits a warning: `mismatched-typevar-name`
T = TypeVar(x)
def g(x: T) -> T:
return x
reveal_type(g(42)) # main: Todo. This PR: `Literal[42]`.
```
## Motivation
The main motivation here is that having a namedtuple or enum with the
"wrong name", for example, just seems much less "obviously wrong" than
having a typevar or paramspec with the "wrong name". The [ecosystem
report](https://github.com/astral-sh/ruff/pull/29957#issuecomment-6603964612)
is evidence of this. namedtuples and enums define runtime classes that
can be used in runtime contexts and instantiated; these constructs
aren't _just_ for type checkers.
TypeVars/ParamSpecs/TypeVarTuples/NewTypes/TypedDicts are all _only_ for
type checkers and there's no plausible reason why you'd want to give the
type a different name to the variable it's assigned to.
`mismatched-namedtuple-name` and `mismatched-enum-name` are therefore
now disabled by default, matching the default severity we already
settled on for `mistmatched-sentinel-name` in
https://github.com/astral-sh/ruff/pull/27206. `mismatched-typevar-name`,
`mismatched-paramspec-name`, `mismatched-typevartuple-name`,
`mismatched-enum-name`, `mismatched-namedtuple-name` and
`mismatched-newtype-name` all remain enabled by default with `warning`
severity.
|
||
|
|
157cae3c06 |
[ty] Honor inline ignores on mismatched ParamSpec components (#30595)
When `**kwargs` is annotated with `P.kwargs`, the matching `*args` annotation must be `P.args`. We emit a diagnostic on `P.args` as a result -- but if you add a suppression comment to that line... a new diagnostic pops up on `P.kwargs`! That's not how suppression comments are really meant to work. This PR fixes that. ## Test plan ### Before (`aa46aae60`) Adding `# ty: ignore[invalid-paramspec]` on the `*args` line moves the diagnostic to `**kwargs`. https://github.com/user-attachments/assets/50ee1858-8126-45bb-896f-2517b98950fe ### After (`684c14273`) Adding the same ignore clears the diagnostic. https://github.com/user-attachments/assets/0a7fc2b0-ffd0-49b4-87ae-714835b7421f |
||
|
|
d1da20cd89 |
[ty] Use control flow checkpoints for statement calls (#30561)
## Summary When a generated UI method calls hundreds of setters, ty walks back through earlier calls to check whether any of them would prevent execution from reaching the current statement. We cache an intermediate result every 256 calls. Between checkpoints we can walk the same calls many times, doing a binary search at each step to see whether we've reached a checkpoint. We now select checkpoints for calls using the same rule we use for other control flow. After walking eight predicates, we look for a checkpoint based on the predicate ID. Nearby statements can reuse a cached result after a shorter walk, and we can drop the search through the list of calls. The closer spacing can retain more Salsa memos in long methods. Cold checks of Shuidi’s generated PyQt6 form used 16.12% fewer instructions. Checking all 89 Python files in Nugget used 7.60–7.76% fewer instructions. [Shuidi revision](https://github.com/MAOGE555/shuidi/blob/6de90e8b9a939c9e57cb2d4f2f2a965668f772f8/new.py) · [Nugget revision](https://github.com/leminlimez/Nugget/tree/26e0c50ec114ca3a4ff6ab2fb4ae309abfd39fa1) Median paired peak RSS rose by 742 KiB on Shuidi. On Nugget the median increase of 1,014 KiB was within the variation between baseline runs. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/248231e9936ecc0e44ecd3a69bc07899736e4e23) | [PR instructions](https://github.com/astral-sh/ruff/commit/ca233b092f1897fbfd658ced1be292c9a38e293d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,179,208,188.5 | 3,160,468,835.5 | -0.59% | -0.71% to -0.47% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,234,941,180 | 8,248,831,934 | +0.13% | -0.02% to +0.17% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) (inconclusive) | 160,010,941,358 | 160,033,050,064 | +0.01% | 0.00% to +0.02% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,841,091,500 | 1,837,145,491 | -0.21% | -0.22% to -0.21% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,930,535,516.5 | 1,921,623,158 | -0.46% | -0.87% to -0.06% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,072,961,014.5 | 30,071,468,706 | 0.00% | -0.03% to +0.02% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,923,102,449 | 2,931,714,627 | +0.29% | 0.00% to +0.42% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,896,852,662.5 | 4,894,400,733 | -0.05% | -0.07% to -0.03% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,352,722,060.5 | 97,951,489,525 | -0.41% | -0.43% to -0.38% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,665,191,727 | 1,665,699,910 | 0.00% | -0.02% to +0.05% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,532,304,774 | 8,508,863,575.5 | -0.27% | -0.30% to -0.25% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,965,330,722.5 | 2,960,677,073.5 | -0.16% | -0.29% to -0.03% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,783,704,471 | 21,796,835,567.5 | +0.06% | -0.06% to +0.18% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,711,695,060.5 | 2,712,229,180.5 | +0.02% | -0.29% to +0.33% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,995,374,688.5 | 13,990,397,766 | -0.04% | -0.11% to +0.04% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,802,092,756.5 | 46,798,119,486.5 | -0.01% | -0.02% to +0.01% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 15,977,459,855 | 15,987,345,132 | +0.07% | +0.06% to +0.10% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,824,268,687 | 8,832,404,265 | +0.07% | +0.07% to +0.25% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,150,396,345.5 | 4,143,422,104.5 | -0.17% | -0.28% to -0.06% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,571,156,422.5 | 14,507,603,093.5 | -0.44% | -0.44% to -0.43% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,001,834,506 | 3,003,583,249 | +0.06% | -0.06% to +0.17% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,828,355,423.5 | 4,826,417,677 | -0.04% | -0.09% to +0.01% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 35,978,090,519 | 35,948,401,773 | -0.08% | -0.13% to -0.03% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 16,468,944,617.5 | 16,445,025,380 | -0.15% | -0.22% to -0.08% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,821,617,408 | 13,840,973,032 | +0.14% | +0.12% to +0.17% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 75,190,375,068 | 75,148,405,537.5 | -0.06% | -0.14% to +0.03% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,980,074,016.5 | 8,973,542,688.5 | -0.07% | -0.13% to -0.01% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 105,060,132,657.5 | 105,002,927,918 | -0.05% | -0.08% to -0.03% | --------- Co-authored-by: Charlie Marsh <charliemarsh@openai.com> |
||
|
|
cbcf866379 |
[ty] Preserve type variable constraints through identity aliases (#30590)
When a generic function expects a callback that returns `Id[R]`, where
`type Id[T] = T`, ty can lose the relationship between `R` and a type
variable from the caller.
```py
from collections.abc import Callable
from typing import reveal_type
type Id[T] = T
def run[R](callback: Callable[[], Id[R]]) -> R:
return callback()
def check[T](callback: Callable[[], T]):
reveal_type(run(callback)) # Before: Unknown. After: T@check.
```
When an alias bound expands to a type variable, record the relationship
between the two variables. In this example, the solver can infer `R`
from the callback's return type `T`.
This is just an edge case Codex noticed, not something that showed up in
real code, so it's quite low priority; it just seemed like a very simple
and clearly correct fix.
|
||
|
|
c8ba04dc06 |
[ty] Memoize more argument assignability checks (#30483)
Memoize some more hot-path argument assignability checks with Salsa. |
||
|
|
aa46aae607 |
[ty] Honor shadowed-type-variable independently for nested classes (#30588)
Disabling `invalid-generic-class` currently also erroneously suppresses
`shadowed-type-variable` diagnostics on nested classes, even when
`shadowed-type-variable` is enabled. With this fix,
`shadowed-type-variable` controls those diagnostics independently.
## Test plan
Save this example as `example.py`.
```python
class Outer[T]:
class Inner[T]:
pass
```
Run `ty check --python-version 3.12 --ignore invalid-generic-class
--error shadowed-type-variable example.py` with a build of ty from each
branch. Before the fix, ty reports no diagnostics. With the fix, it
reports `shadowed-type-variable` for `Inner`’s `T`. Replacing `--error
shadowed-type-variable` with `--ignore shadowed-type-variable`
suppresses the diagnostic.
|
||
|
|
bcd21d9524 |
[ty] Skip assignability queries from string and bytes literals to their builtin types (#30556)
## Summary When ty checks `names: list[str] = ["a", "b"]`, it interns a pair of types and caches an assignability result for each distinct string. The relation checker always accepts a string literal where `str` is expected. We now return that answer before creating the cache key, and do the same for bytes literals where `bytes` is expected. On the emoji table below, ty’s memory report shows that the number of cached assignability results fell from 5,186 to zero. We measured the change in instructions for a cold `ty check` with Cachegrind, running each pair in both orders. | Workload | Base first | PR first | | --- | ---: | ---: | | [transformers-ci emoji table, one file](https://github.com/huggingface/transformers-ci/blob/c740ae2df90c21aaa72b80a79cd5a106cc589912/src/transformersci/_emoji_shortcodes.py) | −9.51% | −9.64% | | [Faker Chinese SSN provider, one file](https://github.com/joke2k/faker/blob/affa2c5aada23fc5c00127298a8e904375d32832/faker/providers/ssn/zh_CN/__init__.py) | −5.63% | −5.65% | | [Packaging source tree](https://github.com/pypa/packaging/tree/929fd4b1410ac7ef61ef3f45b2f5d7e87711a9b5/src/packaging) | −0.26% | −0.77% | | [Jinja source tree](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044/src/jinja2) | −0.56% | +0.34% | | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/248231e9936ecc0e44ecd3a69bc07899736e4e23) | [PR instructions](https://github.com/astral-sh/ruff/commit/1d21e19ae5d7ca40a5cfbacf0c43cbbd276f8c5c) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,173,151,578 | 3,175,888,000 | +0.09% | -0.05% to +0.22% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,239,711,483.5 | 8,239,440,162.5 | 0.00% | -0.05% to +0.05% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) (inconclusive) | 160,008,739,827 | 159,978,023,809.5 | -0.02% | -0.03% to -0.01% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,839,699,389.5 | 1,839,905,941.5 | +0.02% | -0.14% to +0.14% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,928,546,886.5 | 1,924,975,857.5 | -0.18% | -0.62% to +0.25% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,051,485,397.5 | 30,075,559,912 | +0.08% | +0.02% to +0.14% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,928,928,527 | 2,925,684,756.5 | -0.11% | -0.20% to -0.02% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,897,331,183 | 4,895,390,760 | -0.04% | -0.06% to -0.02% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 98,277,500,067 | 98,234,791,522.5 | -0.04% | -0.06% to -0.02% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,665,231,258 | 1,664,963,316.5 | -0.02% | -0.05% to +0.01% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,499,333,648 | 8,580,075,092.5 | +1.19% | +0.26% to +2.19% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,966,282,343.5 | 2,965,691,453 | -0.02% | -0.45% to +0.42% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,762,181,516.5 | 21,790,127,170.5 | +0.13% | -0.12% to +0.37% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,708,444,565.5 | 2,706,033,376 | -0.09% | -0.15% to -0.03% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 14,005,150,628 | 14,001,213,219.5 | -0.03% | -0.21% to +0.15% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,783,816,013 | 46,804,695,220 | +0.05% | -0.05% to +0.07% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 15,975,096,807 | 15,976,682,707 | +0.01% | -0.03% to +0.05% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,830,018,805.5 | 8,828,577,298 | -0.02% | -0.05% to +0.02% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,151,483,329.5 | 4,148,222,628 | -0.08% | -0.14% to -0.01% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,576,818,999 | 14,588,029,367.5 | +0.08% | +0.06% to +0.09% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,005,682,538.5 | 3,006,104,157 | +0.01% | 0.00% to +0.03% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,821,578,278.5 | 4,824,210,310.5 | +0.05% | -0.02% to +0.13% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 35,975,691,969.5 | 35,969,789,129.5 | -0.02% | -0.03% to 0.00% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,474,226,042 | 16,467,508,218 | -0.04% | -0.05% to -0.03% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,828,543,728.5 | 13,829,204,898 | 0.00% | -0.01% to +0.02% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 75,182,874,115 | 75,167,868,298 | -0.02% | -0.03% to -0.01% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,989,371,245 | 8,972,410,908 | -0.19% | -0.21% to -0.16% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 105,046,845,230.5 | 105,049,287,974 | 0.00% | -0.01% to +0.01% | |
||
|
|
ad6a3af804 |
[ty] Avoid checking identical mutable TypedDict field types twice (#30554)
## Summary When comparing two `TypedDict`s, ty checks their mutable field types in both directions so that both reads and writes are safe. For example, Pydantic’s `SetSchema` and `FrozenSetSchema` both declare `items_schema: CoreSchema`. Checking that field in both directions can make ty walk the same recursive union twice. We now reuse the first result when the field types are identical and the check succeeds unconditionally. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/248231e9936ecc0e44ecd3a69bc07899736e4e23) | [PR instructions](https://github.com/astral-sh/ruff/commit/8070ac3923ca5a0ad0e466d3e79e777173490984) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,173,151,578 | 3,168,898,476 | -0.13% | -0.48% to +0.21% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,239,711,483.5 | 8,251,530,324.5 | +0.14% | +0.12% to +0.17% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) (inconclusive) | 160,008,739,827 | 159,998,135,483.5 | -0.01% | -0.01% to -0.01% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,838,176,557 | 1,840,563,359.5 | +0.13% | +0.10% to +0.16% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,928,546,886.5 | 1,928,575,227.5 | 0.00% | -0.53% to +0.54% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,051,485,397.5 | 30,079,114,268.5 | +0.09% | +0.07% to +0.11% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,928,928,527 | 2,926,333,550.5 | -0.09% | -0.14% to -0.03% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,897,331,183 | 4,893,387,171 | -0.08% | -0.10% to -0.06% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 98,277,500,067 | 98,270,332,282 | -0.01% | -0.07% to +0.06% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,665,231,258 | 1,665,643,636.5 | +0.02% | -0.02% to +0.07% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,543,578,111 | 8,520,457,749.5 | -0.24% | -0.75% to +1.09% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,966,282,343.5 | 2,964,321,512.5 | -0.07% | -0.11% to -0.03% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,762,181,516.5 | 21,754,343,170 | -0.04% | -0.09% to +0.02% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,708,444,565.5 | 2,704,362,913.5 | -0.15% | -0.21% to -0.09% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 14,005,150,628 | 14,000,520,608.5 | -0.03% | -0.25% to +0.18% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,783,031,518 | 46,820,580,379 | +0.08% | 0.00% to +0.16% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 15,975,096,807 | 15,974,327,186.5 | 0.00% | -0.06% to +0.05% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,830,018,805.5 | 8,833,628,682 | +0.04% | -0.07% to +0.16% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,148,325,664.5 | 4,149,698,890.5 | +0.03% | -0.07% to +0.13% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,576,818,999 | 14,579,604,714.5 | +0.02% | -0.05% to +0.09% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,005,682,538.5 | 3,005,214,413 | -0.02% | -0.06% to +0.03% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,821,578,278.5 | 4,822,305,196 | +0.02% | -0.04% to +0.07% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 35,975,691,969.5 | 35,974,979,610 | 0.00% | -0.03% to +0.02% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,474,226,042 | 16,466,653,505.5 | -0.05% | -0.07% to -0.02% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,823,114,256 | 12,495,730,368.5 | -9.60% | -9.64% to -9.56% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 75,182,874,115 | 75,200,496,899 | +0.02% | -0.06% to +0.11% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,989,371,245 | 8,991,509,760.5 | +0.02% | 0.00% to +0.05% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 105,046,845,230.5 | 105,055,906,168.5 | +0.01% | -0.04% to +0.05% | Co-authored-by: Charlie Marsh <charliemarsh@openai.com> |
||
|
|
0cbf85880e |
[ty] Collect each reachable constraint once in source order (#30564)
## Summary Before walking a constraint diagram, ty collects the constraint from each node, sorts the list by source order, and examines each constraint’s bound. Nodes with different successors can test the same constraint. While checking Bokeh’s `formatters.py`, one sort received 7,340,031 entries for 46 distinct constraints. [Bokeh example](https://github.com/astral-sh/ty/issues/5063) We now record each reachable constraint at its source-order index as we visit the diagram. Reading the filled positions gives us each constraint once, in the order used to derive relationships between pairs of constraints. We can skip the sort and examine each bound once per constraint. On a cold check of Bokeh’s `src` and `tools/release` (492 files), Cachegrind counted 10.41% and 10.48% fewer instructions in opposite orders. Two adjacent runs of the head differed by 0.056%. Both builds produced the same 686 diagnostics. [Pinned Bokeh revision](https://github.com/bokeh/bokeh/tree/378373772846cdfedc1c641ce9219dcbc34b6b9c) | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/248231e9936ecc0e44ecd3a69bc07899736e4e23) | [PR instructions](https://github.com/astral-sh/ruff/commit/cbd4c9800ec05fd53edef1fe505c811f1aae547e) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,171,706,977.5 | 3,173,312,393.5 | +0.05% | +0.04% to +0.06% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,234,158,986 | 8,241,164,549 | +0.03% | +0.01% to +0.21% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,840,391,653 | 1,838,657,018 | -0.09% | -0.12% to -0.07% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,929,921,234 | 1,931,822,739 | +0.10% | -0.03% to +0.23% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,082,819,307 | 30,059,978,903 | -0.08% | -0.11% to -0.04% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,924,591,569 | 2,923,498,040.5 | -0.04% | -0.12% to +0.05% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,894,335,305 | 4,894,911,011.5 | +0.01% | -0.02% to +0.04% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 98,352,950,073.5 | 98,338,876,450.5 | -0.01% | -0.06% to +0.03% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,665,396,087 | 1,665,423,664.5 | 0.00% | -0.02% to +0.03% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,533,055,257 | 8,550,832,351 | +0.21% | -0.29% to +0.71% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,957,070,580.5 | 2,966,308,391 | +0.31% | +0.12% to +0.51% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,790,076,583 | 21,800,899,655.5 | +0.05% | -0.17% to +0.27% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,713,637,106.5 | 2,708,034,423 | -0.21% | -0.46% to +0.05% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,794,398,039.5 | 46,804,980,842.5 | +0.02% | 0.00% to +0.05% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 15,977,923,329 | 15,984,212,294 | +0.04% | -0.04% to +0.12% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,837,889,051.5 | 8,837,673,785.5 | 0.00% | 0.00% to 0.00% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,149,082,443 | 4,153,649,153.5 | +0.11% | +0.07% to +0.15% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,006,251,725 | 3,004,144,737.5 | -0.07% | -0.09% to -0.05% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,831,230,636.5 | 4,825,843,035.5 | -0.11% | -0.16% to -0.06% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 35,973,468,066 | 35,980,669,260.5 | +0.02% | +0.01% to +0.03% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 16,467,121,598.5 | 16,464,743,699.5 | -0.01% | -0.05% to +0.02% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,830,350,467.5 | 13,841,355,668 | +0.08% | +0.04% to +0.11% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 75,188,876,981.5 | 75,162,033,677 | -0.04% | -0.05% to -0.02% | |
||
|
|
a7ba68b491 |
Bump version to 0.17.6 (#30578)
Co-authored-by: astral-automations-bot[bot] <305554984+astral-automations-bot[bot]@users.noreply.github.com> Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> |
||
|
|
3067e15977 |
[ty] Fix lambda parameter inference with an unsolved ParamSpec (#30547)
## Summary
In this code on ty 0.0.107, `wrap(lambda n: n + 1)` alone works fine,
but passing that same result straight to `register` makes ty report an
error on `n + 1`.
```python
from collections.abc import Callable
def wrap[**P](f: Callable[P, int]) -> Callable[P, int]:
return f
def register[**P](f: Callable[P, int]) -> None: ...
wrap(lambda n: n + 1) # OK
register(wrap(lambda n: n + 1)) # Error in ty 0.0.107
```
`P` stands for all the parameters of the callback. Neither `wrap` nor
`register` says what type `n` has. In the nested call, we wrongly gave
`n` the type of the whole parameter list, `(*args: object, **kwargs:
object)`, and then rejected the addition.
With this fix, `n` stays `Unknown` in both calls. If the callback
signature does give a concrete type for a parameter, ty still uses it.
Fixes astral-sh/ty#5075.
|
||
|
|
7aae7a5312 |
Treat relative imports from .__future__ as ordinary imports (#30260)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com> |
||
|
|
700c1e8424 |
[ty] Move NamedTupleLike to ty_extensions._internal (#30567)
|
||
|
|
46c8e45ab5 |
[ty] Clarify gradual callable assignability tests (#30543)
Address post-land review comments on #30509. |
||
|
|
3e94fa78fd |
[ty] Preserve argument inference for unannotated overload parameters (#30549)
ty could infer `Unknown` for a call when one overload left a parameter
unannotated and another supplied a type for it. In this example,
`first()` has no arguments to infer `T` from, so its return type
defaults to `int` unless the caller supplies an expected type.
```python
from typing import overload, reveal_type
from typing_extensions import Never, TypeVar
T = TypeVar("T", default=int)
def first(*values: T) -> T:
return values[0]
@overload
def choose(value, index: int) -> int: ...
@overload
def choose(value: Never, index: object) -> object: ...
def choose(value, index):
return index
reveal_type(choose(first(), 1)) # previously Unknown, now int
```
Both overloads initially match. The first gives `first()` no expected
type, so it infers `int`. The second infers `Never` for the same
expression. Previously, ty reused `Never` while checking the first
overload and treated the call as ambiguous. It now uses the argument
type inferred for each overload, so the first overload wins.
## Test plan
Checked the original example with a nested `create()` whose return type
is a type variable bounded by `int`. ty reveals `int` for
`choose(create(), 1)`, including when `create()` is replaced by
`next(iter([]))`.
|
||
|
|
0528644c0d |
[ty] Skip enum-complement recognition without exclusions (#30539)
## Summary An enum complement represents an enum with one or more members excluded. When an intersection contains only positive types, ty resolves aliases and looks up enum metadata before it can rule out that representation. We now return as soon as we see that the intersection excludes nothing. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/5203c350a703ece7092d8ef33b51f0878efe56d7) | [PR instructions](https://github.com/astral-sh/ruff/commit/f8c20b44a7f94ad56bc7bf6cc38955c864834567) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,169,252,588.5 | 3,165,880,256 | -0.11% | -0.24% to +0.03% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,244,187,955 | 8,233,671,915 | -0.13% | -0.25% to 0.00% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,984,635,621 | 13,967,593,043 | -0.12% | -0.26% to +0.01% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,970,043,385 | 2,964,955,556.5 | -0.17% | -0.36% to +0.02% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,668,314,018.5 | 1,666,115,454.5 | -0.13% | -0.22% to -0.04% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,842,386,237 | 1,842,311,269 | 0.00% | -0.03% to +0.02% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,921,913,908 | 1,922,481,069.5 | +0.03% | -0.07% to +0.13% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,540,711,202.5 | 8,508,536,779.5 | -0.44% | -0.70% to +0.44% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 15,950,314,544 | 15,949,645,524.5 | 0.00% | -0.03% to +0.03% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,077,107,284.5 | 30,054,346,725 | -0.08% | -0.08% to -0.07% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,924,414,939 | 2,924,205,357 | -0.01% | -0.16% to +0.04% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,890,802,299 | 4,888,655,706.5 | -0.04% | -0.10% to +0.02% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,838,095,226.5 | 8,824,778,889.5 | -0.15% | -0.17% to -0.13% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,130,124,186.5 | 97,988,884,182.5 | -0.14% | -0.16% to -0.13% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,716,917,706 | 2,715,071,981 | +0.16% | -0.10% to +0.20% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,758,498,756 | 21,758,137,452 | 0.00% | -0.02% to +0.02% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (load-sensitive) | 46,766,161,702.5 | 46,705,024,120 | -0.13% | -0.16% to -0.10% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,146,476,878.5 | 4,146,717,063.5 | +0.01% | -0.04% to +0.05% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 14,584,417,608 | 14,573,009,928 | -0.08% | -0.08% to -0.08% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 2,999,038,100.5 | 2,998,375,245.5 | -0.02% | -0.06% to +0.01% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,824,919,019.5 | 4,814,929,659 | -0.21% | -0.29% to -0.12% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 35,885,235,003.5 | 35,849,258,989.5 | -0.10% | -0.10% to -0.10% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 16,439,632,022 | 16,430,069,160.5 | -0.06% | -0.08% to -0.04% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) (inconclusive) | 13,868,047,966 | 13,867,703,384.5 | 0.00% | -0.07% to +0.07% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 75,296,392,345 | 75,035,880,330.5 | -0.35% | -0.40% to -0.29% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,969,239,350.5 | 8,971,986,996 | +0.03% | -0.11% to +0.17% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 104,942,117,909 | 104,912,773,105 | -0.03% | -0.14% to +0.09% | |
||
|
|
e1f6bf0d63 |
[ty] Fix a hang when specializing generic constructors (#30510)
On main, we hang on this snippet:
```python
class Property[T]:
value: T
class Either[T](Property[T]):
def __init__[A, B, C](
self: "Either[A | B | C]",
first: type[Property[A]],
second: type[Property[B]],
third: type[Property[C]],
) -> None: ...
result = Either(Property[float], Property[str | None], Property[bytes])
```
The three arguments determine `A`, `B`, and `C`, so `result` should have
type `Either[float | str | None | bytes]`. Previously, we kept
rebuilding the same union in different orders, treating each order as a
new result, and cycling forever.
ty now substitutes one type variable at a time. It lets other bindings
resolve a cycle before choosing a fixed point or falling back to
`Unknown`. When two variables refer back to each other, ty also checks
their bounds. For example, a constructor’s `int` bound still applies
when the class parameter itself is unbounded.
Fixes astral-sh/ty#5057
I tried all six orders of `A`, `B`, and `C` in the `__init__`
declaration above. With the call unchanged, ty inferred `Either[float |
str | None | bytes]` every time.
## Ecosystem report
Bokeh finished in 20 seconds after timing out at 180 seconds on the
base. Across five other projects, 58 existing diagnostics changed which
unresolved type variables ty displayed. Both revisions rejected the same
operations, and typed array inputs retained their concrete dtype. No
stable diagnostics were added or removed. [Full report for
`baf1faa7`](https://github.com/astral-sh/ruff/pull/30510#issuecomment-6965510325)
|
||
|
|
18c2f5d1a9 |
[ty] Reject union narrowing attempts with failed nested calls (#30217)
When inferring a specialization for a generic call, we try each element of a union return context individually before falling back to the entire union. If a nested call fails during one of those attempts, its error recovery type can make the proposed specialization appear valid even though it isn't. There is an open constraint solver bug (astral-sh/ty#4696) where we don't verify that all solutions collectively "cover" all of the valid specializations of any _non-inferable_ typevars. This can cause us to infer a provisional specialization that is incompatible with the actual arguments of a nested call. We then incorrectly accept the narrowed specialization because the nested call's recovery type satisfies the expected parameter type. For now, we work around this by recording when call binding fails, and threading that information through `InferContext` so that `try_narrow` can reject speculative inference attempts that depend on error recovery. We track these failures even when their diagnostics are suppressed, but ignore failures in unreachable code. For calls with a single candidate signature, we also allow narrowing to succeed when the failed argument corresponds to a parameter whose type contains no typevars, since that argument cannot influence the proposed specialization. There are still limitations around callable unions and overloads, which #27942 will address. Closes astral-sh/ty#4971 |
||
|
|
b6d8e21241 |
[ty] Add project-manager.script = "uv" (#30489)
## Summary This PR adds a new `project-manager` table: ```toml [project-manager] project = "uv" | "auto" | "none" project-mode = "sync" | "metadata" script = "uv" | "none" ``` This PR only implements the script part, but I listed all options to outline where we want to go with this in the future. `script = "uv"` opts in to installing PEP 723 script dependencies with uv (to reduce the need for `TY_UV`). For now, `project-manager.script` defaults to `"none"`, but I plan to change this to `"uv"` in the near future. The new option follows the same configuration precedence as other script settings: * A script with its own `tool.ty` section uses the value from its own table to control whether it uses uv to sync its dependencies or not. * Scripts without a `tool.ty` section use the project level `project-manager.script` For now, overriding the setting based on file patterns isn't supported (I have no strong reason against it, it's mainly to cut scope). `TY_UV` takes precedence over any setting in the configuration (similar to other CLI options that support environment variables). The recommended way to check untrusted code is to set `TY_UV=off`, which overrides `project-manager.script`. For now, we keep supporting `experimental.useUv` for scripts, but the in-editor `configuration.project-manager.script` takes precedence over `experimental.useUv`. ## Why is the setting not under `environment. For projects, setting `project-manager.project = "metadata"` also changes how we discover the project (we prefer the workspace over the closest ty project), and `metadata` doesn't initialize the Python environment. ## LSP watch mode Changing `project-manager.script` at the project level requires saving any open script (or closing and reopening) for the sync to start. This simplified the implementation a fair bit and seems an okay trade off. |
||
|
|
c92a47546c |
[ty] Preserve fixed parameters when comparing gradual callables (#30509)
The "gradual parameters" `*args: Any, **kwargs: Any` are special-cased
to match any possible set of arguments, even when they follow other
"normal" parameters in a signature. But they do not make the _entire_
signature gradual -- calls still must satisfy the other normal
parameters present.
We currently are "too gradual" in our treatment of these signatures,
allowing a callable with an initial typed parameter plus gradual
parameters to be assigned to a callable type that has the wrong type for
its first parameter:
```python
from typing import Any, Callable
def lowercase(value: str, *args: Any, **kwargs: Any) -> str:
return value.lower()
callback: Callable[[int], str] = lowercase # Previously accepted by ty
callback(1) # AttributeError
```
This PR rewrites callable assignability (with a significant net
reduction in Rust LOC!) and now correctly reports the error on this
assignment. The first positional argument binds to `value`, which
requires a `str`. The gradual `*args` and `**kwargs` only describe the
remaining arguments.
Closes astral-sh/ty#5052.
## Ecosystem report
All 104 public ecosystem changes on `8681ef368f` are expected. Most new
errors identify callbacks or overrides that cannot accept an argument
their types promise. [Full ecosystem
report](https://github.com/astral-sh/ruff/pull/30509#issuecomment-6966654399)
|
||
|
|
b0015ad905 |
[ty] Fix variance inference for frozen Pydantic models on 3.12 and earlier (#30452)
## Summary Fixes astral-sh/ty#5035. When targeting Python 3.12 or earlier, infer covariance for read-only fields on Pydantic models frozen through a class keyword or `ConfigDict`. Use the same setter lookup as assignment checking so a custom `__setattr__` keeps the model invariant. On Python 3.13 and later, the synthesized `__replace__` still makes these models invariant. |
||
|
|
f4f75dd70e |
[ty] Handle TypedDict union pairs before other simplifications (#30516)
## Summary When building a union, ty already drops equal `TypedDict` identities and keeps distinct ones. We now make that same decision before trying union simplifications whose shapes cannot match a pair of `TypedDict`s. <!-- ty-pinned-project-instructions:start --> | Project | Base instructions | PR instructions | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,168,443,716 | 3,170,270,249 | +0.06% | -0.09% to +0.21% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,243,563,963 | 8,222,116,502.5 | -0.26% | -0.30% to -0.22% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 13,967,044,319 | 13,952,000,490 | -0.11% | -0.12% to -0.10% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,015,835,881 | 2,973,036,387.5 | -1.42% | -1.44% to -1.40% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,674,254,024.5 | 1,669,154,693 | -0.30% | -0.59% to -0.01% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,840,760,352 | 1,840,617,253 | -0.01% | -0.02% to -0.00% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,918,904,014 | 1,928,471,948 | +0.50% | +0.08% to +0.92% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 15,959,170,358.5 | 15,941,375,574.5 | -0.11% | -0.13% to -0.09% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 30,035,957,211.5 | 30,012,775,625.5 | -0.08% | -0.09% to -0.07% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,921,034,266.5 | 2,926,554,731 | +0.19% | +0.06% to +0.32% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,894,489,657 | 4,894,340,186 | -0.00% | -0.01% to +0.01% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,841,145,231 | 8,833,881,159 | -0.08% | -0.11% to -0.06% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,704,118,065 | 2,707,355,951 | +0.12% | -0.12% to +0.36% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,737,033,782.5 | 21,720,847,925 | -0.07% | -0.10% to -0.05% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,145,976,337.5 | 4,151,133,331 | +0.12% | -0.02% to +0.27% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,549,212,075.5 | 14,544,351,206 | -0.03% | -0.08% to +0.01% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,007,532,033.5 | 3,009,551,370.5 | +0.07% | -0.01% to +0.15% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,831,950,023.5 | 4,835,710,164.5 | +0.08% | +0.07% to +0.09% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 35,657,484,032 | 35,662,007,811.5 | +0.01% | -0.00% to +0.03% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 14,369,578,333.5 | 13,852,874,484.5 | -3.60% | -3.69% to -3.51% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 75,144,682,617.5 | 75,109,650,224 | -0.05% | -0.11% to +0.02% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,971,613,976 | 8,951,751,970 | -0.22% | -0.23% to -0.21% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 104,905,657,814 | 104,906,429,408 | +0.00% | -0.02% to +0.02% | <!-- ty-pinned-project-instructions:end --> |
||
|
|
d84471e739 |
[ty] Preserve compatible overloads when partially binding a union argument (#30446)
On main, `functools.partial` rejects a union-valued keyword when
different overloads accept its members and a required argument is left
for the caller. For example, ty accepts binding `option="text"` or
`option=None` separately, but reports `Expected str, found str | None`
here.
```python
from functools import partial
from typing import overload
@overload
def f(value: int, /, *, option: str) -> str: ...
@overload
def f(value: int, /, *, option: None) -> int: ...
def f(value: int, /, *, option: str | None) -> str | int:
return value if option is None else option
def apply(option: str | None) -> str | int:
bound = partial(f, option=option)
return bound(1)
```
When overload resolution retries with each union member, it matches
parameters again. This used to eliminate both overloads because `value`
was missing. The fix defers the missing-argument check on every match
and keeps all compatible overloads for the eventual call. In the
example, ty infers `str | int` for `bound(1)` because the result depends
on the stored keyword. An explicit override selects the corresponding
overload, so `bound(1, option=None)` returns `int`.
For an overloaded function whose two-positional-argument form requires
`option=None`, a partial `p` that stores an `option` of type `str |
None` rejects `p(1, 2)`. It accepts `p(1, 2, option=None)` because the
caller replaces the stored value.
## Test plan
Checked `partial(datetime.replace, tzinfo=tz)` in Pydantic with the
proposed typeshed sync from #30443, which splits `tzinfo` and `None`
into separate overloads. The fix removed the diagnostic on this call. A
direct check confirmed that the partial accepts a datetime receiver and
a `tzinfo=None` override, and rejects a missing or integer receiver.
[Pydantic call
site](https://github.com/pydantic/pydantic/blob/560f0f96a37d6913afdfddb2de22030ef08e68c3/pydantic/experimental/pipeline.py#L313)
|
||
|
|
45f24aea12 | [ty] Split incompatible TypeIs narrowings into two new rules (#29949) | ||
|
|
a5f0610586 |
[ty] Avoid exponential constraint search in generic constructor inference (#30474)
ty could spend minutes inferring the type of a Bokeh `Either` constructed from a property with 28 literal marker names and a property accepting `str`. To rule out a candidate type, the solver explored combinations of bounds for every marker. Rejecting both bounds for just one marker is already a counterexample. Before searching for a counterexample, ty now tries one path that makes each atomic constraint on it false. It follows that path only while the diagram already has the next node, so it never joins branches or backtracks. If the path reaches false and its assignments are consistent, ty can rule out the candidate immediately. Otherwise it uses the existing exact search. Fixes astral-sh/ty#5046. ## Test plan I checked [Bokeh’s original `dataspec.py`](https://github.com/bokeh/bokeh/blob/1c2309202d8623ede74a996a367f3b60eaf79411/src/bokeh/core/property/dataspec.py#L408-L409) with the base and PR Linux binaries, the same checker configuration, and Bokeh’s dependencies in a Python 3.12 environment. The base binary exceeded a 20-second timeout. Removing just the reported constructor call let it finish in 0.69 seconds. The PR binary checked the unmodified file in 0.80 seconds with no diagnostics. Using Bokeh’s classes directly, it also accepted `assert_type(Either(MarkerType, Regex("^@.*$")), Either[str, str])`. |
||
|
|
1e0a2ce2e3 |
[ty] Check fixed prefixes when assigning ParamSpec callables to gradual Concatenate (#30470)
## Summary
ty previously accepted `call_with_int(callback)` below, even though a
caller can pass `forward` a function that takes no arguments.
```python
from typing import Callable, Concatenate
def call_with_int(callback: Callable[Concatenate[int, ...], None]) -> None:
callback(1)
def forward[**P](callback: Callable[P, None]) -> None:
call_with_int(callback) # now an error
```
Check the fixed positional parameters before the caller's `ParamSpec`
against the prefix required by `Concatenate`. This also rules out
overloads that require more positional parameters than the callback
guarantees.
This fixes a bug that otherwise caused new false-positive regressions on
https://github.com/astral-sh/ruff/pull/30423.
## Ecosystem report
The public run for `deb2cd0da5` found three expected changes across 165
projects. ty now reports a missing class receiver in a
pytest-autoprofile wrapper annotation and removes two incorrect
overload-related errors in discord.py. [Full ecosystem
report](https://github.com/astral-sh/ruff/pull/30470#issuecomment-6927397479).
|
||
|
|
51b50bd771 |
[ty] Fix stack overflow checking a generic base initializer (#30473)
ty used to abort with a stack overflow while checking this
`super().__init__` call. It now reports `invalid-argument-type` on
`value` in `super().__init__(value)`.
```python
class Box[T]:
def __init__[A, B](self: "Box[A]", value: A | tuple[B]) -> None: ...
class Child[T](Box[bytes]):
def __init__(self, value: T | tuple[T]) -> None:
super().__init__(value)
```
The receiver for that call is a `Child[T]`, which is already a
`Box[bytes]`. That fixes `A` to `bytes`. A one-element tuple is valid
because the initializer can infer `B = T`. But `Child[str]("hello")`
would forward a plain string where the initializer expects `bytes` or a
tuple.
ty now uses the receiver’s existing class type arguments when checking a
constructor method. Looking up the method on a bare generic class still
allows the call to infer those arguments.
The stack overflow happened while ty was trying to explain the failed
call. It combined type-variable bindings inferred from individual
arguments, then repeatedly substituted them into each other. A cycle
through a tuple element can add another layer of `tuple[...]` on every
substitution. The original reproducer had the same problem with a
callable’s return type. ty now drops the parts of a binding that would
keep growing and uses the remaining evidence to report the error.
Fixes https://github.com/astral-sh/ty/issues/5047
## Test plan
Compared the CLI on the merge base and this change using the example
above and the original reproducer in both PEP 695 and legacy `TypeVar`
syntax. All three aborted on the merge base and produced argument-type
diagnostics on this change. The example above passes with `Box[T]` as
the base.
## Ecosystem report
On `3c94d4a654a3c2cc6a05b4845d4057271599ebb0`, six new diagnostics
identify constructors that accept arguments incompatible with the
receiver’s specialization. The change also removes a false return
warning in PyMongo and simplifies two existing setuptools diagnostics.
All nine changes were reproduced, with no new regressions found. [Full
ecosystem
report](https://github.com/astral-sh/ruff/pull/30473#issuecomment-6931764426)
|
||
|
|
1d40d153a9 |
[ty] Document runtime support in ty-extensions (#30497)
## Summary The `ty-extensions` package lets Python evaluate and inspect `Intersection[A, B]` and `Not[A]` at runtime. Update the stub docstrings and the `experimental-syntax` documentation to point readers to the package. |
||
|
|
0222c19dd8 |
Share ty configuration for Ruff’s standalone scripts (#30463)
## Summary Use a shared ty override for Ruff’s standalone scripts now that PEP 723 scripts can inherit project settings. Fix the diagnostics in the two PR automation scripts so they can use the same checks. ## Notes to reviewers All 28 standalone scripts passed ty with locked dependencies, and the changed-file hooks and mocked workflow checks passed. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com> |
||
|
|
a42b3d2779 |
[ty] Split invalid dataclass __post_init__ signatures into a separate rule (#30335)
|
||
|
|
82bb2810cc |
[ty] Speed up materialization of nested generic types (#30462)
Checking nested calls to a generic overload can spend most of its time materializing the same type arguments repeatedly. For a type such as `Row[Row[Any]]` with a covariant parameter, each layer could visit its argument twice to compute the same top materialization. This doubles the work with each layer. Compute the top materialization lazily and reuse it when comparing the argument with its materialization or constructing the result. This also skips the top traversal when only the bottom materialization is needed. Improves astral-sh/ty#5041. ## Test plan I timed the reproducer from the issue on macOS arm64 using an optimized debug build. Checking eight nested overloaded calls went from 29.05 s to 1.55 s. To isolate materialization from overload resolution, I also checked `Top` applied to 23 nested `Row` types. That went from 3.08 s to 0.03 s. Both examples passed before and after the change. |
||
|
|
1e1361d149 | [ty] Use the constraints rule for single-constraint TypeVar calls (#30340) | ||
|
|
244668339a |
Adopt new APIs from Rust 1.98 (#30419)
Summary -- - The first commit uses [strip_circumfix] to remove paired delimiters in one call. - The second commit uses [map_or_default] to combine many `map` and `unwrap_or_default` calls. - The third commit uses [bool::ok_or] to turn boolean checks into `Result<(), E>` values. - The fourth commit uses [str::substr_range] to get the byte range of a TODO directive directly from the comment. The last commit is slightly more involved than the others, as Codex found a panic in the old code if a `HACK` TODO comment used the Kelvin sign as its `K` and added a test showing that `substr_range` helped to fix it. That seems absurdly niche, but the new code is simpler anyway. There's also a new [format_into] API for formatting integers into a `NumBuffer` and bypassing some `Display` overhead. We could use this in the `UP031` fix, but it makes the code a bit more complicated and seemed worth trying and benchmarking separately to see if it's worth the trouble. [strip_circumfix]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.strip_circumfix [map_or_default]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.map_or_default [bool::ok_or]: https://doc.rust-lang.org/stable/std/primitive.bool.html#method.ok_or [str::substr_range]: https://doc.rust-lang.org/stable/std/primitive.str.html#method.substr_range [format_into]: https://doc.rust-lang.org/stable/core/primitive.usize.html#method.format_into |
||
|
|
e517fdc45f |
Update Rust toolchain to 1.100 and MSRV to 1.98 (#30416)
Summary -- There were several new cargo and clippy lints here, so I tried to break up the changes into several commits: - deleting some unused workspace dependencies, these looked kind of intentional as they also had some shear ignores, but it seems okay to delete those too? - allowing the [redundant_homepage] lint. We could delete a lot of these, but the ones in the `ruff` and `ty` crates seem necessary for maturin, as I noted in a comment. - fixing the [missing_lints_inheritance] lint. It seems that several of our crates don't inherit our workspace lints. For now I just included the `allow` for `redundant_homepage`, but we could follow up by inheriting the full table and fixing all the additional lints that produces. (This commit is actually combined with the previous one) - allowing cargo's new [unused_dependencies] lint, which seems redundant with `shear` and had some false positives on our benchmark dependencies. Codex tried to work around this with some `cfg`-gated imports in the benchmark crate, but ignoring this seemed better for now, at least while we're still using `shear`. - running `clippy --fix` on the remaining lint errors, with one manual intervention where Clippy dropped some of our `cfg` handling. These new diagnostics were mostly around returning boolean expressions. - renaming `NodeIndex::_NONE` to avoid [used_underscore_items] There are also some new APIs in 1.98 that we can use now. I'll follow up with those separately. [redundant_homepage]: https://doc.rust-lang.org/cargo/reference/lints.html#redundant_homepage [missing_lints_inheritance]: https://doc.rust-lang.org/cargo/reference/lints.html#missing_lints_inheritance [used_underscore_items]: https://clippy.rust-lang.org/master/#used_underscore_items [unused_dependencies]: https://doc.rust-lang.org/cargo/reference/lints.html#unused_dependencies |
||
|
|
4357fa3666 |
[ty] Split missing-module-member out of import-not-found (#30342)
|
||
|
|
36b92bb23e |
[ty] Check protocol member names before specializing the source interface (#30445)
## Summary When comparing generic protocols, ty specializes the source’s members before discovering that a required member is missing. We now check the first required name that `object` doesn’t provide. If the source and its base classes lack that name, we can reject the comparison immediately. The larger NumPy check saved 0.15% of instructions. A successful 49-member protocol stress case used 0.36% more. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/6bf61927fd328ff83b36ea6484a86dfedc53c340) | [PR instructions](https://github.com/astral-sh/ruff/commit/dda61822347385a7a4e4d3d1cb0634079a0ed9d6) | Change | Paired range | | :--- | ---: | ---: | ---: | :--- | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,189,153,694 | 3,195,522,185 | +0.20% | +0.13% to +0.27% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,271,324,202.5 | 8,287,035,400 | +0.19% | +0.15% to +0.23% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 14,008,171,426 | 14,029,005,636.5 | +0.15% | +0.10% to +0.20% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,018,892,189 | 3,027,247,422 | +0.31% | -0.35% to +0.52% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 160,164,140,559.5 | 160,055,392,562.5 | -0.07% | -0.09% to -0.05% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,675,421,289 | 1,672,311,473 | -0.18% | -0.58% to +0.21% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,841,755,068 | 1,842,190,245 | +0.02% | +0.01% to +0.04% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,935,895,714 | 1,927,851,995 | -0.42% | -0.58% to -0.25% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 9,016,906,198.5 | 8,616,683,232 | -4.44% | -4.87% to -4.00% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 15,995,025,094.5 | 15,965,301,708.5 | -0.19% | -0.19% to -0.18% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 30,305,048,327 | 30,134,727,537 | -0.56% | -0.65% to -0.47% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,940,012,272.5 | 2,934,812,358 | -0.18% | -0.24% to -0.11% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,906,149,744.5 | 4,906,045,674 | 0.00% | -0.05% to +0.04% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,845,062,801.5 | 8,838,006,594.5 | -0.08% | -0.08% to -0.08% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,275,445,653.5 | 98,164,087,812 | -0.11% | -0.12% to -0.11% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,712,880,137.5 | 2,709,082,810.5 | -0.14% | -0.50% to +0.22% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,843,482,137.5 | 21,869,645,614.5 | +0.12% | +0.11% to +0.13% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,763,163,715.5 | 46,736,979,809 | -0.06% | -0.07% to -0.04% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,155,722,484.5 | 4,161,983,049 | +0.15% | +0.13% to +0.17% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,596,829,668 | 14,600,743,257.5 | +0.03% | +0.02% to +0.03% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,001,284,986.5 | 3,000,941,623.5 | -0.01% | -0.07% to +0.05% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,826,870,671 | 4,831,000,527.5 | +0.09% | +0.03% to +0.14% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 36,475,564,934.5 | 36,148,279,180 | -0.90% | -0.92% to -0.88% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,659,677,357 | 16,513,941,898.5 | -0.87% | -0.95% to -0.80% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 15,923,299,274 | 15,905,062,087.5 | -0.11% | -0.17% to -0.06% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 77,921,923,652 | 76,916,522,116.5 | -1.29% | -1.37% to -1.21% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,950,615,809.5 | 8,952,371,055.5 | +0.02% | -0.04% to +0.08% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 105,278,037,248 | 105,048,269,879 | -0.22% | -0.23% to -0.20% | |
||
|
|
9523a9c4b2 |
[ty] Avoid definition lookups in recursive TypedDict comparisons (#30444)
## Summary When ty compares two `TypedDict`s, it checks whether it has already seen the same recursive comparison. Just ruling out a match used to require looking up both class definitions in the semantic index. On Pydantic, this was hot even when comparing unrelated classes. We now compare the class body scopes directly. Each static class has its own body scope, even if decorators change the inferred class. The cycle detector still confirms a possible match as before. No new cache is needed. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/6bf61927fd328ff83b36ea6484a86dfedc53c340) | [PR instructions](https://github.com/astral-sh/ruff/commit/5e990b50038313b3823b163c92e5b185d84ae8f1) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,190,053,839.5 | 3,188,241,010.5 | -0.06% | -0.25% to +0.14% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,259,374,385 | 8,273,184,860.5 | +0.17% | +0.13% to +0.21% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 14,001,184,223.5 | 14,011,332,236.5 | +0.07% | 0.00% to +0.15% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,025,802,232.5 | 3,008,598,981 | -0.57% | -0.82% to -0.32% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 160,215,011,062 | 160,207,933,299 | -0.00% | -0.01% to +0.00% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,673,282,803 | 1,673,246,216.5 | -0.00% | -0.22% to +0.22% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,843,059,788 | 1,844,450,255 | +0.08% | -0.00% to +0.16% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,928,721,892 | 1,926,416,699 | -0.12% | -0.30% to +0.07% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 8,958,396,167.5 | 8,969,914,964 | +0.13% | -0.17% to +0.43% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 16,000,188,103 | 15,988,082,034 | -0.08% | -0.10% to -0.05% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 30,312,056,762.5 | 30,352,688,313.5 | +0.13% | +0.01% to +0.26% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,947,385,062 | 2,948,535,288 | +0.04% | -0.16% to +0.24% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,907,754,594.5 | 4,905,679,459.5 | -0.04% | -0.06% to -0.02% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,849,672,821.5 | 8,856,795,249.5 | +0.08% | +0.07% to +0.09% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,301,163,943 | 98,225,138,861 | -0.08% | -0.12% to -0.04% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,709,709,778.5 | 2,714,149,963.5 | +0.16% | -0.08% to +0.41% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,857,396,126 | 21,845,368,544.5 | -0.06% | -0.16% to +0.05% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,743,486,541 | 46,744,399,446 | 0.00% | -0.09% to +0.09% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,161,325,878 | 4,162,546,498.5 | +0.03% | -0.00% to +0.06% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,608,429,663 | 14,596,174,263 | -0.08% | -0.18% to +0.01% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 3,003,082,894.5 | 3,002,930,681 | -0.01% | -0.02% to +0.01% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,825,905,235.5 | 4,830,880,175.5 | +0.10% | 0.00% to +0.21% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 36,489,353,458 | 36,468,164,350 | -0.06% | -0.06% to -0.06% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,654,074,392.5 | 16,661,866,206 | +0.05% | +0.04% to +0.05% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 15,921,444,387 | 14,374,354,228.5 | -9.72% | -9.73% to -9.70% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 77,952,541,396.5 | 77,935,694,925.5 | -0.02% | -0.05% to +0.01% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,965,385,292.5 | 8,961,380,316 | -0.04% | -0.14% to +0.05% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 105,264,942,428.5 | 105,294,114,319 | +0.03% | -0.05% to +0.10% | |
||
|
|
6bf61927fd |
[ty] Skip repeated validation lookups for checked overloads (#30436)
## Summary NumPy declares 12 overloads for a two-input ufunc’s `__call__`. ty validates them together, but each later declaration still looks up `__call__` and searches the overload list before discovering it has already checked the function. We now skip that lookup once we’ve checked the function. We mark the name only after confirming that the declaration belongs to the final binding, so a shadowed overload can’t hide an error. <!-- ty-pinned-project-instructions:start --> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/a3a3ebb53b88e674b0ca5a5ae7073e59ad6a632a) | [PR instructions](https://github.com/astral-sh/ruff/commit/11ca77182bb6c9367dda4776c7bcb32dba96358b) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,179,359,403 | 3,184,076,407 | +0.148% | -0.094% to +0.391% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,313,325,060 | 8,306,108,151 | -0.087% | -0.104% to -0.069% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 14,069,678,550 | 14,064,857,470 | -0.034% | -0.089% to +0.020% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,039,259,507 | 3,039,894,405 | +0.022% | -0.374% to +0.418% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 160,645,285,368 | 160,604,334,577 | -0.025% | -0.040% to -0.011% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,678,606,471 | 1,673,781,547 | -0.287% | -0.546% to -0.028% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,845,860,070 | 1,845,691,719 | -0.009% | -0.089% to +0.071% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,930,161,827 | 1,928,335,327 | -0.095% | -0.109% to -0.080% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 9,316,701,164 | 9,132,652,691 | -1.973% | -2.703% to -1.243% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 16,407,634,386 | 16,409,015,669 | +0.008% | -0.040% to +0.057% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 30,775,629,618 | 30,789,599,834 | +0.045% | -0.017% to +0.107% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 3,029,939,701 | 3,018,524,070 | -0.377% | -0.498% to -0.255% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,954,489,753 | 4,955,503,918 | +0.020% | +0.010% to +0.031% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,888,414,042 | 8,875,858,423 | -0.141% | -0.242% to -0.040% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,629,376,442 | 98,441,202,077 | -0.191% | -0.196% to -0.185% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,711,985,392 | 2,723,630,294 | +0.429% | -0.013% to +0.872% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 22,000,854,584 | 22,038,118,004 | +0.169% | +0.076% to +0.263% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 47,067,269,630 | 47,056,404,837 | -0.023% | -0.042% to -0.004% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,180,062,606 | 4,180,053,331 | 0.000% | -0.107% to +0.106% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,606,015,011 | 14,592,109,699 | -0.095% | -0.144% to -0.047% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,993,687,809 | 2,993,586,242 | -0.003% | -0.084% to +0.077% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,835,399,821 | 4,827,997,713 | -0.153% | -0.165% to -0.141% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 36,728,366,144 | 36,730,670,668 | +0.006% | -0.019% to +0.032% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,764,346,451 | 16,762,888,565 | -0.009% | -0.017% to -0.001% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 19,245,306,247 | 19,234,942,877 | -0.054% | -0.072% to -0.036% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 79,422,056,365 | 79,428,755,147 | +0.008% | -0.008% to +0.025% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 9,037,040,882 | 9,021,919,086 | -0.167% | -0.175% to -0.160% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 106,103,809,632 | 106,088,000,463 | -0.015% | -0.042% to +0.012% | <!-- ty-pinned-project-instructions:end --> |
||
|
|
8e61f26585 |
[ty] Avoid tracking ordinary instances twice in type searches (#30438)
## Summary When ty searches `list[T]` for a type variable, it records both the list instance and its specialized class in the visited set. The search reaches `T` through the class, which already has its own entry to prevent cycles. We now check the instance for a match and continue at its class. Exact tuples such as `tuple[int, T]` keep their entry in the visited set because ty visits their elements directly. | Project | Base instructions | PR instructions | Change | Paired range | |:---|---:|---:|---:|---:| | [black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,140,211,040 | 3,130,582,486 | -0.31% | -0.52% to -0.10% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 8,234,494,974 | 8,186,053,684 | -0.59% | -0.79% to -0.39% | | [django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 13,856,506,770 | 13,839,681,276 | -0.12% | -0.17% to -0.08% | | [fastapi](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 3,005,708,492 | 2,987,717,997 | -0.60% | -0.83% to -0.36% | | [homeassistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 159,179,865,788 | 158,533,269,512 | -0.41% | -0.42% to -0.40% | | [httpx](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,654,218,058 | 1,648,052,978 | -0.37% | -0.54% to -0.20% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,823,066,808 | 1,818,833,308 | -0.23% | -0.29% to -0.17% | | [jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,903,792,912 | 1,901,397,362 | -0.13% | -0.46% to +0.19% | | [numpy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 9,256,027,288 | 9,125,220,567 | -1.54% | -2.01% to -0.12% | | [openai](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 16,201,787,514 | 15,919,739,652 | -1.74% | -1.81% to -1.67% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 30,406,145,253 | 30,054,267,782 | -1.16% | -1.18% to -1.14% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,988,628,376 | 2,913,863,198 | -2.52% | -2.63% to -2.41% | | [prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,866,236,294 | 4,848,466,288 | -0.37% | -0.43% to -0.30% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,785,701,267 | 8,753,029,740 | -0.37% | -0.39% to -0.36% | | [pytorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 97,622,906,862 | 97,257,727,334 | -0.37% | -0.39% to -0.36% | | [rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,680,413,388 | 2,681,361,922 | -0.03% | -0.27% to +0.84% | | [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 21,760,084,566 | 21,613,566,540 | -0.67% | -0.72% to -0.62% | | [sympy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 46,426,241,316 | 46,280,811,675 | -0.31% | -0.33% to -0.30% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 4,128,285,865 | 4,111,708,768 | -0.40% | -0.47% to -0.33% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,443,518,089 | 14,393,487,338 | -0.35% | -0.43% to -0.26% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,972,531,318 | 2,966,731,613 | -0.20% | -0.20% to -0.19% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 4,778,783,225 | 4,772,818,870 | -0.12% | -0.14% to -0.11% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 36,409,748,222 | 36,054,790,464 | -0.97% | -1.04% to -0.91% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 16,601,347,367 | 16,489,651,412 | -0.67% | -0.68% to -0.66% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 19,143,927,938 | 19,131,203,006 | -0.07% | -0.08% to -0.05% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 78,927,370,390 | 77,369,933,078 | -1.97% | -2.04% to -1.90% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 8,894,392,684 | 8,870,129,222 | -0.27% | -0.31% to -0.24% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 104,672,743,496 | 104,191,109,944 | -0.46% | -0.49% to -0.43% | |
||
|
|
8f325682e9 |
[ty] Reuse unpacked field types across TypedDict union candidates (#30437)
## Summary
When ty checks `{**source}` against a union of `TypedDict`s, it computes
the fields of `source` for each destination. If `source` is also a
union, each pass walks all its arms. For one literal in Pydantic, ty
computed the same fields 59 times.
We now reuse those fields for each distinct source type within a single
literal. Each destination checks them against its own schema, and later
entries in the literal take precedence when keys overlap.
| Project | Base instructions | PR instructions | Change | Paired range
|
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 3,144,977,237.5 | 3,144,005,841 | -0.03% | -0.08% to +0.02% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 8,237,195,473.5 | 8,250,488,169 | +0.16% | +0.02% to +0.30% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 13,848,832,671 | 13,896,492,321 | +0.34% | +0.33% to +0.36% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,999,027,232.5 | 2,998,004,083.5 | -0.03% | -0.12% to +0.05% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 159,281,366,036 | 159,406,426,533.5 | +0.08% | +0.08% to +0.08% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,654,576,852 | 1,654,218,442.5 | -0.02% | -0.14% to +0.10% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,822,860,299 | 1,823,577,176.5 | +0.01% | -0.11% to +0.16% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,907,674,472 | 1,913,445,512.5 | +0.30% | +0.28% to +0.33% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 9,169,849,017.5 | 9,203,795,609.5 | +0.28% | -0.91% to +1.36% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 16,216,591,694 | 16,221,296,595 | +0.03% | -0.02% to +0.08% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 30,414,704,764 | 30,401,947,671.5 | -0.04% | -0.09% to +0.01% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,993,677,646.5 | 2,987,666,491.5 | -0.20% | -0.25% to -0.15% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 4,869,496,964.5 | 4,871,176,864 | +0.03% | +0.02% to +0.05% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 8,790,428,048.5 | 8,801,225,568 | +0.12% | +0.06% to +0.18% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 97,698,230,779 | 97,836,356,208 | +0.14% | +0.12% to +0.16% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 2,686,816,690.5 | 2,692,072,356 | +0.20% | +0.03% to +0.37% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 21,723,248,781 | 21,765,746,781.5 | +0.20% | +0.13% to +0.26% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 46,424,379,247 | 46,483,354,311.5 | +0.13% | +0.12% to +0.14% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 4,124,670,648 | 4,125,740,439.5 | +0.03% | +0.01% to +0.04% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 14,444,767,054.5 | 14,459,699,340.5 | +0.13% | +0.05% to +0.20% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,968,960,967.5 | 2,973,202,753.5 | +0.15% | +0.05% to +0.30% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 4,772,406,894 | 4,775,638,224.5 | +0.07% | +0.02% to +0.12% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 36,417,089,865 | 36,438,535,586.5 | +0.06% | +0.06% to +0.06% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 16,591,143,336 | 16,605,788,430 | +0.09% | +0.06% to +0.12% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 19,149,354,661.5 | 17,309,402,460.5 | -9.61% | -9.65% to -9.57% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 78,916,455,450 | 78,958,980,917 | +0.05% | +0.03% to +0.08% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 8,893,304,512.5 | 8,901,319,644 | +0.09% | +0.04% to +0.14% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 104,656,623,123 | 104,812,208,646 | +0.15% | +0.14% to +0.16% |
|
||
|
|
f970a87170 |
[ty] Skip discarded TypedDict validation diagnostics in union matching (#30435)
## Summary
When ty checks a dictionary literal against a union of `TypedDict`s, it
tries each arm. A key that belongs to one arm can look like a typo in
another, so ty may format a diagnostic and suggest a correction that it
immediately discards.
We now infer the keys and values first, then skip building diagnostics
while deciding which arms match. A literal like `{"foo": len(text,
text)}` still reports the extra argument when it matches the arm that
defines `foo`.
| Project | Base instructions | PR instructions | Change | Paired range
|
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 3,140,770,360.5 | 3,137,027,790.5 | -0.12% | -0.13% to -0.11% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 8,232,469,551 | 8,233,123,492 | +0.01% | -0.03% to +0.05% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 13,859,221,971.5 | 13,850,681,780.5 | -0.06% | -0.08% to -0.04% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,999,919,456.5 | 2,996,875,136 | -0.10% | -0.13% to -0.07% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 159,297,355,749 | 159,179,851,629.5 | -0.07% | -0.08% to -0.06% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,654,221,315.5 | 1,653,379,684.5 | -0.05% | -0.11% to +0.01% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,822,079,469.5 | 1,823,644,659.5 | +0.09% | +0.01% to +0.16% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,911,129,017.5 | 1,909,878,478.5 | -0.04% | -0.39% to +0.16% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 9,168,060,822.5 | 9,192,749,321 | +0.50% | -0.59% to +1.14% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 16,227,951,746.5 | 16,169,160,912 | -0.36% | -0.42% to -0.31% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 30,369,536,534 | 30,408,037,258 | +0.13% | -0.03% to +0.29% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,997,011,422.5 | 2,994,138,124.5 | -0.13% | -0.18% to +0.40% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 4,869,509,965.5 | 4,866,197,388.5 | -0.07% | -0.07% to -0.06% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 8,790,503,701.5 | 8,793,045,752 | +0.03% | +0.02% to +0.03% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 97,691,773,077 | 97,621,020,649 | -0.07% | -0.11% to -0.04% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 2,679,007,117.5 | 2,685,852,674 | +0.26% | -0.15% to +0.93% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 21,735,030,895 | 21,746,256,356.5 | +0.05% | -0.05% to +0.15% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 46,442,197,060 | 46,431,993,374 | -0.02% | -0.05% to +0.01% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 4,121,467,960 | 4,122,545,338.5 | +0.03% | +0.00% to +0.05% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 14,440,181,295 | 14,434,430,642.5 | -0.04% | -0.09% to +0.01% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,970,886,867.5 | 2,972,717,691.5 | +0.06% | -0.01% to +0.13% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 4,787,468,353.5 | 4,778,570,944 | -0.19% | -0.41% to +0.04% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 36,417,108,086.5 | 36,372,823,323 | -0.12% | -0.15% to -0.09% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 16,594,410,623 | 16,577,662,309.5 | -0.10% | -0.13% to -0.07% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 19,145,306,834 | 17,675,871,133 | -7.68% | -7.69% to -7.66% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 78,898,298,589 | 78,936,186,295 | +0.05% | +0.04% to +0.06% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 8,903,677,644.5 | 8,889,536,056 | -0.16% | -0.29% to -0.03% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 104,695,484,029.5 | 104,637,217,395 | -0.06% | -0.07% to -0.04% |
|