mirror of
https://github.com/astral-sh/ruff.git
synced 2026-12-04 02:03:58 +08:00
main
2509
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b976635837 |
[ty] Port annotations/string.md to use inline snapshots (#31320)
## Summary The motivation here is that I'd like to fix some bugs in some of these diagnostics, and that involves adding more snapshots, but the snapshots are painful to review when they use external `.snap` files. The new examples expose some issues in our existing diagnostics; some TODOs are added in this PR for places where our diagnostics are suboptimal. |
||
|
|
8af2925ca3 |
[ty] Narrow tagged unions through nested type aliases (#31210)
When a type alias is one member of a tagged union, ty used to keep the
entire alias if any of its members matched the tag. This could produce a
false missing-attribute error on a branch where only one class was
possible.
```python
from typing import Literal
class A:
kind: Literal["a"]
x: int
class B:
kind: Literal["b"]
class C:
kind: Literal["c"]
type Inner = A | B
def f(v: Inner | C) -> int:
if v.kind == "a":
return v.x
return 0
```
Previously, ty narrowed `v` to `A | B` and reported that `B` has no
attribute `x`. Now it checks each alternative inside `Inner`, narrows
`v` to `A`, and accepts `v.x`. The same filtering applies to value
patterns, identity checks, and truthiness checks on attributes.
A comparison can also rebind `v` after reading its tag. In that case, ty
skips narrowing the new value based on the old one.
Closes https://github.com/astral-sh/ty/issues/5171
|
||
|
|
d14dd3df62 |
[ty] Infer ParamSpecs from whole unions (#31209)
## Summary Fixes astral-sh/ty#5132. Use the same whole-union inference for `ParamSpec` that we already use for ordinary type variables. This was originally carved out because ParamSpec wasn't supported in the new constraint solver -- but now it is, so we can remove the carve-out. ```py from typing import Callable def require_callback[**P](value: Callable[P, bool] | int) -> Callable[P, bool]: if isinstance(value, int): raise TypeError return value def check(x: Callable[[str], bool] | int): callback = require_callback(x) callback(1) ``` Previously ty inferred `(...) -> bool` and accepted `callback(1)`. Now it infers `(str, /) -> bool` and reports the bad argument. The callable arm determines the parameter list. The `int` arm places no constraints on it. ## Ecosystem report The [ecosystem run](https://github.com/astral-sh/ruff/actions/runs/46736502360/attempts/1) for [`ee4c4449e6`](https://github.com/astral-sh/ruff/commit/ee4c4449e62618d048fc3a923c4058000e728957) found 37 diagnostic changes across three projects. I reproduced all of them and found no ecosystem blocker for review. - discord.py loses three return warnings because the command decorators keep their callback parameters. - Prefect recovers the signature of its sync/async wrapper. That exposes gaps in the wrapper’s annotations. Two existing errors in Dask and Ray also change wording. - steam.py now uses the declared default for the command owner when a callback can match the arm without an owner. That exposes two registrations whose annotations don’t tie the command to the registry’s owner type. An existing ignore covers one. [Full analysis and reduced examples](https://github.com/astral-sh/ruff/pull/31209#issuecomment-7331938045) |
||
|
|
bbc17f6c6d |
[ty] Avoid quadratic memory use when comparing enums with possible aliases (#31290)
Comparing a large enum with a string could take quadratic time and
memory when ty couldn't tell which enum names were aliases. On the
400-member reproducer, peak memory dropped from 213 MiB to 42 MiB.
```py
from enum import StrEnum
class Code(StrEnum):
A = "A".lower()
B = "a".lower()
def compare(code: Code, text: str):
if code != text:
reveal_type(text) # now str
```
Previously, ty inferred `(str & ~Literal[Code.A]) | (str &
~Literal[Code.B])`. This only rules out a value if the two names are
aliases, as they are here at runtime. When ty can't prove that, building
the union can require comparing every pair of excluded members.
We now stop narrowing as soon as two alternatives exclude different enum
literals. Comparing against one specific member still excludes it. The
same applies when ty knows that all the names refer to one member.
Fixes astral-sh/ty#5206.
## Test plan
I varied the enum size in the issue reproducer and measured peak RSS
separately from ty's memory report. At 400 members the number of cached
`exclusion_is_covered` results fell from 319,200 to zero. It stayed at
zero at 3,200 members, where peak RSS was 52 MiB. I also checked both
operand orders and the unequal branch of `==`.
|
||
|
|
e869fe7888 |
[ty] Preserve NewType when binding Self in callbacks (#31231)
## Summary Calling a `NewType` instance directly preserves `Self`, but passing it as a callback could lose the `NewType`. For example, after #31211 ty rejected the assignment to `callback` below because it thought `clone.__call__` returned `Cloner`. ```py from typing import NewType, Protocol, Self class Cloner: def __call__(self) -> Self: return self NewCloner = NewType("NewCloner", Cloner) class SelfCallback(Protocol): def __call__(self) -> Self: ... def example(clone: NewCloner): callback: SelfCallback = clone ``` The assignment now passes. A generic callback protocol can also infer `NewCloner` as the return type, just as `clone()` does. This works by looking up `__call__` on the base class while binding `Self` to the original receiver. The same binding applies when checking a plain `Callable`. Follow-up to #31211 and astral-sh/ty#5172. ## Notes to reviewers This also affects `Self` in parameter types. For `__call__(self, other: Self) -> Self`, ty now rejects assigning a `NewType` instance to a callback that must accept every instance of the base class. That matches how ty checks an ordinary subclass. A direct call can still infer a wider `Self` from both arguments. ## Test plan I compared the callback checks on main and with the fix. A nested `NewType` now keeps its outermost type through a generic callback. An explicit base-class return annotation still gives the base class. I also checked that a metaclass-supplied `__call__` and a base that inherits from `Any` retain their previous `Callable` assignability. |
||
|
|
dea95d5aa6 |
[ty] Avoid exponential narrowing after mapping class patterns (#31279)
## Summary
Checking what can reach the second case after `Mapping()` or `dict()`
could take exponentially longer as the subject union grew.
```python
from collections.abc import Mapping
class A: ...
class B: ...
def f(x: A | B) -> None:
match x:
case Mapping():
pass
case A():
pass
```
A subclass of either `A` or `B` could implement `Mapping`. Previously,
ty subtracted `(A & Mapping) | (B & Mapping)` to find what reaches the
second case. Negating that union can double the number of intermediate
types for each additional class.
Now ty subtracts `Mapping` directly. It still accounts for extra runtime
matches. For example, `dict()` always matches a `TypedDict` value, even
when its static type isn't a subtype of `dict`.
Fixes astral-sh/ty#5187.
## Test plan
I timed the original reproduction with `anthropic==0.105.0` and Python
3.15 on macOS using optimized debug builds. Checking it went from about
169 seconds to 84 ms. With 12 ordinary classes, the example above went
from 3.85 seconds to 31 ms. Replacing `Mapping()` with `dict()` went
from 3.71 seconds to 32 ms.
|
||
|
|
a225eefff7 |
[ty] Add tests for resetting automatic Django primary keys (#30068)
## Summary Django lets you clear an automatic primary key before saving a copy of a model instance. ty currently rejects assigning `None` to `pk` or `id`, as well as assigning an `int | None` value to `pk`. |
||
|
|
efac287cf3 |
Report missing parentheses around yield and generator expressions (#31192)
## Summary Today, Ruff’s parser accepts the following expressions inside a function even though CPython rejects them. | Invalid syntax | How Ruff parses it today | Valid syntax | | --- | --- | --- | | `yield if flag else None` | A conditional with a bare `yield` in the true branch | `(yield) if flag else None` | | `(yield, 1)` | A tuple with a bare `yield` as its first element | `((yield), 1)` | | `(yield x for x in xs)` | A generator expression with `yield x` as its element | `yield (x for x in xs)` | | `(yield from x for x in xs)` | A generator expression with `yield from x` as its element | `yield from (x for x in xs)` | This PR reports `invalid-syntax` for all four cases by checking that an expression starting with `yield` matches Python’s [`yield_expr` rule](https://github.com/python/cpython/blob/v3.15.2/Grammar/python.gram#L727-L729) in full. The first two cases report “Unparenthesized yield expression cannot be used here”. This wording also replaces “Yield expression cannot be used here” for syntax Ruff already rejected, such as `1, yield x`. The last two cases report “Unexpected `yield` before the first `for` clause in a generator expression”. Ruff underlines `yield` in all four examples. It checks the generator element when it reaches the first `for` or `async for`, so syntax errors in the iterable can be reported independently. Fixes #31178. ## Notes to reviewers Please review this PR commit by commit. 1. Reword the existing yield diagnostic and update its snapshots. [ |
||
|
|
e55c1f074c |
[ty] Model Django pk as a writable property (#31269)
## Summary Django exposes `pk` as a writable property. If an ebook has a UUID primary key, `ebook.pk.hex` is valid, but accessing `Ebook.pk.hex` raises `AttributeError` at runtime. ty now reports the missing attribute on the class. The synthesized property uses the field’s read and write types separately so assignments can still accept Django expressions where the field allows them. Addresses [this finding on #29785](https://github.com/astral-sh/ruff/pull/29785#discussion_r4455622885). Stacked on #31268. |
||
|
|
4d3fece769 |
[ty] Django: Follow the stored ID when to_field points to a relation (#31268)
## Summary Addresses [this finding on #29785](https://github.com/astral-sh/ruff/pull/29785#discussion_r4455684391). |
||
|
|
ca6d664f26 |
[ty] Report all classes in overlapping inheritance cycles (#31298)
## Summary ty can miss a `cyclic-class-definition` error depending on the order of the base classes. For example, in this stub: ```pyi class A(B): ... # Missing error class B(C): ... class C(B, A): ... ``` When checking `A`, we follow `A → B → C → B` and stop as soon as we see `B` again. We never visit `C`'s second base, so we conclude that `A` inherits from a cycle but isn't part of one. Swapping the bases to `class C(A, B)` reports the error on `A` as expected. We now record that we found a cycle and continue with the remaining bases. That lets us find the path back to `A` without reporting an error on a class that only inherits from `B`, like `class D(B)`. |
||
|
|
b2a5f53bde |
[ty] Recognize from pkgutil import extend_path in legacy namespace packages (#31274)
## Summary
Today, ty only recognizes legacy namespace packages that use `__path__ =
pkgutil.extend_path(__path__, __name__)`, but it doesn't recognize the
same pattern if the code only imports `extend_path`.
I analyzed the top 10k pypi packages and there are more usages of
`extend_path` than `pkgutil.extend_path`, suggesting that we should
support it
Callee | Calls | Projects | Calls inside try or if
-- | -- | -- | --
`extend_path` | 773 | 64 | 1
`pkgutil.extend_path` | 31 | 17 | 15
`__import__("pkgutil").extend_path` | 822 | 295 | 7
`_extend_path` | 2 | 2 | 0
`_pkgutil.extend_path` | 1 | 1 | 0
This PR extends our legacy namespace detection to support top-level
* `from pkgutil import extend_path`
* `from pkgutil import extend_path as _extend_path`
* `import pkgutil as _pkgutil`
The `extend_path` call must be at the top-level, without any compound
statements, or assignment to the variable, between the call and the
import.
The approach implemented in this PR covers all cases in the table except
for calls inside `try` or `if` statements. There's an argument that we
should support compound statements also. I suggest we tackle this in a
separate PR.
I verified that this fixes the legacy namespace package related
unresolved-imports to 0.
Fixes astral-sh/ty#5194.
|
||
|
|
cc5cf6f4f9 |
[ty] Reduce memory use when looking up inherited methods on large unions (#31288)
## Summary
Looking up `item.link` on a union of 400 subclasses used to cache
159,600 comparisons when all the subclasses inherited the same method.
Just reading the attribute was enough.
```py
class Base:
def link(self) -> None: ...
class A(Base): ...
class B(Base): ...
def lookup(item: A | B):
method = item.link
```
Both methods wrap `Base.link`, but their `__self__` types differ. Since
neither `A` nor `B` inherits from the other, neither bound method can
cover the other. We can keep both without caching a comparison in either
direction.
This reuses the ancestry check we already use for unions of instances.
We still visit each pair and fall back to the full comparison when the
receivers might be related.
Fixes astral-sh/ty#5205.
## Test plan
I compared `ty check` before and after on macOS arm64. Peak RSS is the
median of five runs per build.
- On the original 400-subclass registry, peak RSS fell from 69.9 MB to
47.6 MB. The Salsa memory report showed zero cached redundancy checks,
down from 159,600.
- On the reduced example with 800 subclasses, peak RSS fell from 147.6
MB to 62.0 MB. Replacing the lookup with `pass` let me isolate the
memory attributable to the lookup. That fell from 90.4 MB to 0.81 MB in
the Salsa report.
|
||
|
|
282b1b56cc |
[ty] Skip redundant merges at exception handlers (#31260)
## Summary
We take a snapshot of the current bindings at each operation that can
raise. We merge those snapshots to work out which values an `except`
handler can see, as in:
```py
def send(message: str | None) -> None:
try:
connect()
if message is not None:
write(message)
except OSError:
log(message)
```
If `connect()` raises, `message` can be `str | None`. If `write()`
raises, it can only be `str`. Merging `str` into `str | None` tells us
nothing new.
We now skip that merge for a variable or attribute if an earlier
snapshot on the same path has the same binding and pending constraints.
We still merge bindings from sibling branches and account for
reassignments between calls.
At saturation (i.e., if we have too many nodes), this change can
introduce or remove diagnostics, but precision after saturation is best
effort anyway, so it's a toss-up vs. main.
<!-- ty-pinned-project-instructions:start -->
| Cold `ty check` | Mean change | Largest change | Projects with a lower
median |
| --- | ---: | ---: | ---: |
| Instructions | −0.51% | −2.68% (Black) | 27/28 |
| Peak RSS | +0.05% | +0.64% (HTTPX) | 14/28 |
[Open
WebUI](https://github.com/open-webui/open-webui/blob/926f826eaef6179c092a936eede6c7363e425975/backend/open_webui/utils/middleware.py#L4838-L6633)
has hundreds of calls in a single `try` block. In a separate
single-worker check on Linux, we executed 5.64% fewer instructions and
reported the same 2,510 diagnostics.
<details>
<summary>Instruction counts by project</summary>
We ran cold `ty check` on Linux (x86-64) with one worker. We applied the
PR to the linked base. Each count is the median of four Cachegrind runs.
Changes are medians of the paired percentages. We let ty discover the
files in each project, including 359 files in NumPy. We mark a change
inconclusive if the pairs disagree in direction or the change falls
within the variation between runs.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/3af52e2584db23f286ffd6a42d1159a3b1873626)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/e207bb8a4c83171309383aea058a0b302d4e63d6)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,332,769,811 | 2,270,349,502.5 | -2.68% | -2.68% to -2.67% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,540,936,926 | 5,474,959,096.5 | -1.19% | -1.19% to -1.18% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 110,804,818,135 | 110,303,836,829.5 | -0.45% | -0.45% to -0.45% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,285,867,278 | 1,284,723,998.5 | -0.09% | -0.09% to -0.09% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
(inconclusive) | 1,320,366,514.5 | 1,320,406,056.5 | 0.00% | 0.00% to
+0.01% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 19,933,018,002.5 | 19,922,728,370 | -0.05% | -0.06% to -0.05% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,234,689,069.5 | 2,234,278,738.5 | -0.02% | -0.02% to -0.01% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,710,976,179 | 3,679,704,575 | -0.84% | -0.84% to -0.84% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 67,274,964,402.5 | 66,472,389,299 | -1.19% | -1.20% to -1.19% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,180,889,603.5 | 1,172,069,895 | -0.75% | -0.75% to -0.74% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 28,315,534,060.5 | 28,287,483,288.5 | -0.10% | -0.10% to -0.09% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,213,490,643.5 | 2,185,580,183 | -1.26% | -1.26% to -1.26% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,438,836,220.5 | 14,431,269,932 | -0.05% | -0.06% to -0.05% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,952,582,115 | 1,946,784,020 | -0.30% | -0.30% to -0.28% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,655,605,122.5 | 9,626,021,177 | -0.31% | -0.31% to -0.31% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 30,790,105,517.5 | 30,744,415,104 | -0.15% | -0.15% to -0.15% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,582,742,893 | 10,506,743,173 | -0.72% | -0.72% to -0.72% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,043,447,137.5 | 6,039,481,561.5 | -0.07% | -0.07% to -0.06% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 2,983,479,489.5 | 2,930,792,608 | -1.77% | -1.77% to -1.76% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,254,446,880.5 | 10,216,229,135.5 | -0.37% | -0.38% to -0.37% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,131,197,347 | 2,117,947,315.5 | -0.62% | -0.63% to -0.61% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,430,711,968.5 | 3,415,339,277 | -0.45% | -0.45% to -0.45% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 23,566,286,719.5 | 23,464,640,331 | -0.43% | -0.44% to -0.43% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 10,715,499,306 | 10,714,176,347 | -0.01% | -0.02% to -0.01% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,086,347,875.5 | 6,067,057,239 | -0.32% | -0.32% to -0.31% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 36,244,132,706 | 36,228,584,838 | -0.04% | -0.05% to -0.04% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,374,469,607 | 6,368,168,631 | -0.10% | -0.10% to -0.10% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 68,690,540,782.5 | 68,662,581,709.5 | -0.04% | -0.04% to -0.04% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS changes are medians of 16 pairs at default parallelism and four
with one worker. The last two columns estimate retained Salsa storage
after diagnostics. We ran two single-worker pairs per mode. We froze
file inputs in both builds for the frozen column, as in a one-shot
check. The standard memory report leaves them mutable.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| +0.01 (+0.01%) | 8/16 | −0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.05 (+0.03%) | 8/16 | −0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.04 (0.00%) | 8/16 | −0.03 | −0.01 (0.00%) | −0.01 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +0.12 (+0.17%) | 8/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.01 (−0.02%) | 8/16 | +0.11 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +0.62 (+0.12%) | 9/16 | +0.07 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.16 (−0.13%) | 6/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.15 (−0.08%) | 7/16 | +0.04 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −0.06 (0.00%) | 7/16 | +0.19 | −0.01 (0.00%) | −0.01 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.55 (+0.64%) | 10/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +0.76 (+0.18%) | 9/16 | +0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| +0.54 (+0.46%) | 11/16 | +0.05 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.11 (−0.03%) | 7/16 | −0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.01 (−0.01%) | 8/16 | +0.08 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| +0.40 (+0.15%) | 11/16 | −0.04 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −0.10 (−0.02%) | 6/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| +0.44 (+0.16%) | 10/16 | −0.08 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.30 (−0.14%) | 5/16 | −0.14 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.21 (−0.18%) | 7/16 | −0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.36 (−0.14%) | 5/16 | −0.19 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.12 (+0.11%) | 11/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| +0.15 (+0.11%) | 9/16 | +0.03 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.18 (−0.03%) | 7/16 | −0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| +0.08 (+0.03%) | 8/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −0.10 (−0.09%) | 6/16 | −0.12 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| +0.01 (0.00%) | 8/16 | +0.04 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.17 (+0.08%) | 9/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −1.21 (−0.08%) | 7/16 | −0.25 | 0.00 (0.00%) | 0.00 (0.00%) |
</details>
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
d9d2f531b9 |
[ty] Preserve base-class attribute types on NewType instances (#31234)
After #31211, ty could lose information about an attribute when checking a `NewType` against a protocol. For example, wrapping an integer-valued enum made its `value` look like `Any`, so ty accepted a protocol that promised a string. ```python from enum import Enum from typing import NewType, Protocol class E(Enum): A = 1 B = 2 N = NewType("N", E) class HasStringValue(Protocol): @property def value(self) -> str: ... def f(n: N): reveal_type(n.value) # Previously Any, now Literal[1, 2] p: HasStringValue = n # Now an error ``` Member lookup now uses the underlying class to find enum attributes, attributes installed by a metaclass, and the input type of a dataclass field converter. It still binds `Self` to the original receiver, preserving the fix for astral-sh/ty#5172. This also makes enum literals and other enum instances use the same rules for deciding when a descriptor overrides the generated name or value. ## Notes to reviewers There is some overlap with #26678 in how a `NewType` finds an attribute installed by a metaclass. This PR keeps the existing precedence rules for metaclass writes. Using the nominal class for lookup also applies to class-backed protocols. If a custom metaclass installs an attribute on the protocol, ty can infer that attribute on a structural implementation that doesn't actually have it. ## Test plan I checked a member named `value` with an inherited `enum.property` and an ordinary mixin property on CPython 3.11 through 3.15. All five versions used the inherited enum getter when present and the enum payload otherwise. |
||
|
|
71a4da3dc3 |
[ty] Django: auto-completion for generated members (#31272)
## Summary Add auto-completion for generated members on Django models. Follow-up to [Carl's suggestion in #29651](https://github.com/astral-sh/ruff/pull/29651#discussion_r4353848880). |
||
|
|
d68383b0fd |
[ty] Group equivalent TypedDict.get keys (#30897)
Calls with a union of known keys could match the broad string fallback before argument expansion, losing their field types. Group keys with the same declared value type and requiredness into an exact literal-key overload. Required and optional groups retain their existing default handling. Keys in different groups keep their existing fallback behavior. ## Ecosystem report At [`c9ff292711`](https://github.com/astral-sh/ruff/commit/c9ff2927111f6015a505065ad321f40f46cd744c), the more precise lookup types expose two truthiness warnings in Home Assistant and remove two spurious warnings in Prefect. All four changes are expected and none block merging. See the [full ecosystem report](https://github.com/astral-sh/ruff/pull/30897#issuecomment-7356194259) for examples. --------- Co-authored-by: Carl Meyer <carl@astral.sh> |
||
|
|
f13c638103 |
[ty] Defer parameter unions when filtering overloads (#31250)
## Summary When several overloads match a call, we build and simplify a union of the parameter types at each argument position to decide how many overloads to keep. We can often tell when to stop without building those unions. ```pyi from typing import overload @overload def f(x: bytes, y: object) -> str: ... @overload def f(x: object, y: str) -> str: ... @overload def f(x: object, y: object) -> object: ... ``` Suppose `x` and `y` both have type `Any`. The first overload alone isn't enough because `x` could be a plain `object()`. After the second overload, we've seen an `object` parameter at both positions. We can drop the fallback and infer `str`. We now track which positions still exclude a plain object and which accept every value as we visit each overload. If that doesn't settle the question, we build the unions in declaration order, including any overloads we skipped, and check assignability as before. <!-- ty-pinned-project-instructions:start --> | Cold `ty check` | Mean change | Largest change | Projects with a lower median | | --- | ---: | ---: | ---: | | Instructions | −0.24% | −4.01% (NumPy) | 17/28 | | Peak RSS | −0.07% | −1.02% (NumPy) | 16/28 | On a separate check of [SciPy](https://github.com/scipy/scipy/tree/99a9e746aae9afb575ad0336a11ad17c567ed97a/scipy), instruction counts fell by 1.10% and peak RSS fell by 4.88 MiB. Both builds reported the same diagnostics. <details> <summary>Instruction counts by project</summary> We let `ty check` discover files in each project and kept the source files intact. We compared the linked base commit with the same commit plus this patch. Counts are medians of four single-worker Cachegrind runs on Linux (x86-64). Change is the median of four paired percentages. We marked a result inconclusive when the pairs disagreed in direction or the change was within the variation between runs of either build. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/4f9f81365e68a8cba902271140fb602619d298da) | [PR instructions](https://github.com/astral-sh/ruff/commit/70bfbf8bc40d12f7f8cc56056a5d511a7a8e6f2f) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,334,323,713 | 2,333,992,652.5 | -0.01% | -0.02% to -0.01% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,541,526,773.5 | 5,540,005,586 | -0.03% | -0.03% to -0.02% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 110,884,325,272 | 110,950,690,719 | +0.06% | +0.06% to +0.06% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,281,362,190 | 1,281,338,871 | 0.00% | 0.00% to 0.00% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,318,512,592.5 | 1,318,586,383 | +0.01% | 0.00% to +0.01% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 19,975,044,939 | 19,867,422,467 | -0.54% | -0.54% to -0.54% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,232,061,053.5 | 2,232,575,740 | +0.02% | +0.01% to +0.03% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 3,715,431,447 | 3,717,174,617 | +0.05% | +0.04% to +0.05% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 67,323,295,296 | 67,322,032,502 | 0.00% | -0.01% to +0.01% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,181,255,058.5 | 1,181,611,847 | +0.03% | +0.03% to +0.04% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 28,309,919,449.5 | 27,174,140,216.5 | -4.01% | -4.01% to -4.01% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,218,845,670.5 | 2,217,465,517 | -0.06% | -0.08% to -0.06% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 14,488,047,350.5 | 14,489,491,428 | +0.01% | +0.01% to +0.01% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 1,952,125,293 | 1,951,393,898.5 | -0.04% | -0.04% to -0.04% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 9,686,380,847 | 9,687,193,951.5 | +0.01% | +0.01% to +0.01% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 30,813,365,062 | 30,805,345,325 | -0.03% | -0.03% to -0.02% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 10,598,846,055 | 10,570,318,522.5 | -0.27% | -0.27% to -0.27% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 6,051,366,880 | 6,051,515,354 | 0.00% | 0.00% to +0.01% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 2,985,360,427 | 2,986,117,599 | +0.03% | +0.02% to +0.03% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,235,015,215.5 | 10,236,357,773 | +0.01% | +0.01% to +0.02% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,142,696,058.5 | 2,141,733,882 | -0.04% | -0.05% to -0.04% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,440,883,112 | 3,439,747,269.5 | -0.03% | -0.03% to -0.03% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 23,616,050,068.5 | 23,476,699,534.5 | -0.59% | -0.59% to -0.58% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 10,722,822,187.5 | 10,714,649,470 | -0.08% | -0.08% to -0.07% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,108,938,020 | 6,085,572,342 | -0.38% | -0.38% to -0.38% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 36,257,927,598 | 35,943,962,078 | -0.87% | -0.87% to -0.86% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,396,895,831.5 | 6,395,689,979.5 | -0.02% | -0.02% to -0.02% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 68,769,875,491.5 | 68,806,219,132 | +0.05% | +0.05% to +0.05% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median change across 16 pairs at default parallelism and four with one worker. The last two columns estimate retained Salsa storage after diagnostics, using two single-worker pairs per mode. For the frozen column, we enabled file input freezing in both builds during memory reporting, as in a one-shot check. For the mutable column, we used the stock report, as in CI. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) | | --- | ---: | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | −0.26 (−0.24%) | 7/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | +0.39 (+0.22%) | 9/16 | +0.12 | −0.01 (−0.01%) | −0.01 (−0.01%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | −0.10 (0.00%) | 6/16 | +0.07 | −0.15 (−0.01%) | −0.14 (0.00%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | −0.07 (−0.10%) | 8/16 | +0.26 | 0.00 (−0.02%) | 0.00 (−0.01%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | +0.02 (+0.03%) | 8/16 | −0.13 | 0.00 (−0.01%) | 0.00 (−0.01%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +0.51 (+0.10%) | 10/16 | −1.61 | −1.23 (−0.32%) | −1.64 (−0.37%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | +0.51 (+0.39%) | 9/16 | +0.38 | 0.00 (0.00%) | 0.00 (0.00%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | +0.01 (0.00%) | 8/16 | +0.17 | 0.00 (0.00%) | 0.00 (0.00%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | −0.21 (−0.02%) | 5/16 | −0.49 | −0.14 (−0.01%) | −0.16 (−0.01%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | −0.04 (−0.05%) | 6/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | −4.45 (−1.02%) | 0/16 | −7.11 | −6.05 (−1.85%) | −8.76 (−2.16%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.25 (+0.22%) | 8/16 | +0.29 | −0.01 (−0.01%) | −0.01 (−0.01%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | +0.01 (0.00%) | 8/16 | −0.18 | −0.13 (−0.05%) | −0.16 (−0.05%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.01 (−0.01%) | 8/16 | +0.07 | 0.00 (0.00%) | 0.00 (0.00%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | −0.25 (−0.09%) | 6/16 | −0.02 | −0.06 (−0.03%) | −0.06 (−0.03%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | −0.08 (−0.01%) | 6/16 | −0.18 | −0.26 (−0.06%) | −0.30 (−0.05%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | +0.18 (+0.07%) | 9/16 | +0.40 | 0.00 (0.00%) | 0.00 (0.00%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | −0.18 (−0.09%) | 8/16 | +0.12 | −0.01 (0.00%) | −0.01 (0.00%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.43 (−0.38%) | 4/16 | +0.11 | 0.00 (0.00%) | 0.00 (0.00%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | +0.01 (+0.01%) | 8/16 | −0.15 | −0.08 (−0.04%) | −0.08 (−0.04%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.02 (−0.01%) | 7/16 | −0.19 | −0.03 (−0.05%) | −0.03 (−0.05%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.09 (+0.07%) | 9/16 | −0.06 | −0.01 (−0.01%) | −0.02 (−0.02%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −0.80 (−0.15%) | 6/16 | −0.79 | −0.52 (−0.12%) | −0.87 (−0.18%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | −0.51 (−0.20%) | 2/16 | −0.36 | −0.16 (−0.09%) | −0.20 (−0.09%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | −0.23 (−0.20%) | 7/16 | −0.10 | −0.01 (−0.01%) | −0.01 (−0.01%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −3.14 (−0.58%) | 0/16 | −3.40 | −2.73 (−0.65%) | −3.80 (−0.72%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | +0.06 (+0.03%) | 8/16 | −0.09 | −0.02 (−0.01%) | −0.02 (−0.01%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +1.64 (+0.11%) | 10/16 | −0.35 | −0.22 (−0.02%) | −0.18 (−0.01%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
0f5a3f786a |
[ty] Preserve Hashable narrowing for NewTypes based on object (#31232)
## Summary After #31211, ty could miss an attribute error because it assumed every value of a `NewType` based on `object` was hashable. But `Tag([])` is still a list. ```py from collections.abc import Hashable from typing import NewType Tag = NewType("Tag", object) tag = Tag([]) if not isinstance(tag, Hashable): reveal_type(tag) # was Never, now Tag & ~Hashable tag.missing # now reports missing-attribute ``` The same rule that applies to `object` now applies to `Tag` and to nested `NewType`s based on it. They remain assignable to `Hashable`, but `Tag | Hashable` keeps both alternatives. Protocol member checks still bind `Self` to the original `NewType`, preserving the fix for astral-sh/ty#5172. |
||
|
|
1300cc3cae | [ty] Report IPython escape commands in type expressions instead of panicking (#31238) | ||
|
|
845b16a8de |
[ty] Add autofixes for mismatched-*-name diagnostics (#30628)
|
||
|
|
0cb37dba08 |
[ty] Infer the return type of struct.unpack_from from the format string (#31230)
Given the same format, ty inferred two integers from
`struct.unpack("<QQ", buf)` but treated both values as `Any` when
reading from an offset via `struct.unpack_from`. There's no reason for
these two functions not to both be handled the same way.
```python
a, b = struct.unpack_from("<QQ", buf, 0)
```
Now ty infers `int` for both `a` and `b`.
Closes astral-sh/ty#5176
## Ecosystem report
At
[`6aee62f23b`](https://github.com/astral-sh/ruff/commit/6aee62f23bed5d15004e6fd0fc5f90334a7f1d1b),
more precise tuple types clear nine warnings across six projects. Both
new diagnostics are in aiortc. One flags a redundant cast. The other
flags a conversion from a list to a tuple where the annotation loses the
pair’s length.
All eleven changes are expected. I found no regressions that block
review. [Full ecosystem
report](https://github.com/astral-sh/ruff/pull/31230#issuecomment-7333269462).
|
||
|
|
1b6e76ab88 |
[ty] Preserve NewType when solving Self through a protocol (#31211)
|
||
|
|
055bc9d1d9 |
[ty] Check subscript assignments on negated types (#30011)
## Summary
Today, adding an `is not None` check makes an `invalid-assignment` error
disappear in ty.
```python
def write(out: object) -> None:
out[0] = 1 # error: [invalid-assignment]
if out is not None:
out[0] = 1 # No error
```
Inside the `if`, we narrow `out` to `~None`. This is equivalent to
`object & ~None`, but we leave the `object` implicit.
When checking a subscript assignment, we look for a positive element of
the intersection that supports `__setitem__`. Here, there are no
explicit positive elements, so we skip the check entirely. We also skip
inferring the types of the index and value, which trips an assertion in
debug builds.
We now fall back to `object` in this case, just as we do for subscript
reads. Since `object` doesn't define `__setitem__`, we report
`invalid-assignment` on both lines.
The [ecosystem
check](https://github.com/astral-sh/ruff/pull/30011#issuecomment-6620456227)
now flags the same [two slice assignments in
`array_api_compat`](https://github.com/scikit-learn/scikit-learn/blob/d5a61d1149cb94a936d4b32212330f4ba8f24ce0/sklearn/externals/array_api_compat/torch/linalg.py#L85-L107)
in both scikit-learn and SciPy.
<!-- ty-pinned-project-instructions:start -->
Measured 22 of 28 projects.
<details>
<summary>Instruction counts by project</summary>
Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/f4460e6a246c3c5946c378a493a4b0477f96b5b6)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/64ad0f4432bc25503eb5590c0d33348adb1f7133)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
(inconclusive) | 5,520,030,120 | 5,519,734,639 | 0.00% | -0.01% to 0.00%
|
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
(inconclusive) | 1,276,799,329.5 | 1,276,831,914.5 | 0.00% | 0.00% to
+0.01% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
(inconclusive) | 2,228,216,697 | 2,228,247,302.5 | 0.00% | -0.01% to
0.00% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
(inconclusive) | 3,700,911,803 | 3,700,863,299 | 0.00% | -0.01% to 0.00%
|
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
(inconclusive) | 67,020,678,458.5 | 67,021,118,877 | 0.00% | 0.00% to
0.00% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
(inconclusive) | 1,173,461,193.5 | 1,173,469,899.5 | 0.00% | -0.01% to
0.00% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 6,848,360,174.5 | 6,848,472,121 | 0.00% | 0.00% to
0.00% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
(inconclusive) | 2,219,922,569.5 | 2,219,876,593.5 | 0.00% | -0.01% to
+0.01% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
(inconclusive) | 14,424,050,600.5 | 14,424,529,543 | 0.00% | 0.00% to
+0.01% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
(inconclusive) | 1,937,265,850.5 | 1,937,238,641 | 0.00% | -0.01% to
0.00% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
(inconclusive) | 9,675,889,910.5 | 9,676,125,165.5 | 0.00% | -0.01% to
+0.01% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
(inconclusive) | 30,782,177,712 | 30,781,433,537 | 0.00% | -0.01% to
0.00% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
(inconclusive) | 10,589,722,261 | 10,589,792,313.5 | 0.00% | 0.00% to
0.00% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
(inconclusive) | 6,001,224,061.5 | 6,001,333,347 | 0.00% | 0.00% to
0.00% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
(inconclusive) | 2,981,316,229 | 2,981,343,761.5 | 0.00% | 0.00% to
0.00% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
(inconclusive) | 10,248,763,240.5 | 10,248,399,560 | 0.00% | 0.00% to
0.00% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
(inconclusive) | 2,148,555,675 | 2,148,560,003.5 | 0.00% | 0.00% to
0.00% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
(inconclusive) | 3,430,920,927 | 3,430,935,373.5 | 0.00% | 0.00% to
0.00% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
(inconclusive) | 23,607,686,762.5 | 23,607,918,625.5 | 0.00% | -0.01% to
0.00% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
(inconclusive) | 10,718,082,586 | 10,717,986,927 | 0.00% | -0.01% to
0.00% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
(inconclusive) | 6,076,631,621 | 6,076,392,380.5 | 0.00% | -0.01% to
0.00% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
(inconclusive) | 6,384,670,422.5 | 6,384,635,228.5 | 0.00% | 0.00% to
0.00% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median change across 16 pairs at default parallelism and
four with one worker. The last two columns estimate retained Salsa
storage after diagnostics, using two single-worker pairs per mode. For
the frozen column, we enabled file input freezing in both builds during
memory reporting, as in a one-shot check. For the mutable column, we
used the stock report, as in CI. A dash marks a pending measurement.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Frozen Salsa (MiB) | Mutable Salsa (MiB) |
| --- | ---: | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| — | — | — | 0.00 (0.00%) | — |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.12 (−0.07%) | 7/16 | +0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| — | — | — | 0.00 (0.00%) | — |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.29 (−0.41%) | 7/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| — | — | — | 0.00 (0.00%) | — |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| — | — | — | 0.00 (0.00%) | — |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.63 (−0.49%) | 6/16 | −0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| +0.47 (+0.25%) | 10/16 | +0.13 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +0.08 (+0.01%) | 9/16 | +0.24 | — | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.29 (+0.34%) | 12/16 | −0.07 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +1.13 (+0.51%) | 10/16 | −0.02 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| +0.27 (+0.23%) | 8/16 | −0.14 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| +0.03 (+0.01%) | 8/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.48 (+0.48%) | 11/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.19 (−0.07%) | 3/16 | +0.11 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +0.42 (+0.07%) | 12/16 | +0.09 | 0.00 (0.00%) | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.03 (−0.01%) | 7/16 | −0.21 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| +0.06 (+0.03%) | 10/16 | −0.05 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.15 (−0.13%) | 7/16 | 0.00 | — | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.21 (−0.08%) | 6/16 | +0.18 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 0.00 (0.00%) | 8/16 | +0.01 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.10 (−0.07%) | 6/16 | −0.06 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.15 (−0.03%) | 7/16 | +0.10 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.12 (−0.04%) | 5/16 | +0.19 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −0.03 (−0.03%) | 7/16 | −0.18 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| — | — | — | 0.00 (0.00%) | — |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.08 (−0.04%) | 6/16 | −0.14 | 0.00 (0.00%) | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| — | — | — | 0.00 (0.00%) | — |
</details>
<!-- ty-pinned-project-instructions:end -->
|
||
|
|
2d98a75ba5 |
[ty] Skip lambda bodies when collecting loop bindings (#31150)
## Summary
ty reports that `reset` conflicts with an instance slot at the `for`
statement below. It then reports a missing attribute when we assign to
`Queue().reset`.
```py
class Queue:
__slots__ = ("reset",)
for _ in (1,):
push = lambda: (reset := 1)
Queue().reset = 1 # Valid
```
When we collect the names a loop can bind, we walk into the lambda body
and record a binding for `reset` in the class. That suppresses the slot
descriptor, even though `reset` is local to the lambda.
We now skip the lambda body and visit its parameter defaults. For
example, in `lambda arg=(value := 1): (result := arg)`, only `value` is
bound in the enclosing scope.
The bug surfaced while testing #30108, where renaming the lambda could
change the diagnostic for nested loops.
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
fbabe4c5e1 |
[ty] Preserve literals outside a sequence when simplifying unions (#30996)
## Summary
ty rejects the call below because it drops both literals from the union.
`"aa"` is a sequence of `"a"` characters, but `"ab"` is still a valid
argument in its own right. Reversing the union members makes ty accept
the call.
```py
from collections.abc import Sequence
from typing import Literal
def f(x: Literal["aa", "ab"] | Sequence[Literal["a"]]): ...
f("ab")
```
When we add a sequence to a union that already contains string or bytes
literals, we now check each literal for redundancy. This also handles
sequences nested inside intersections. Previously we used the first
literal to decide whether to keep the entire group, so we could also
keep redundant literals when the first one fell outside the sequence.
|
||
|
|
00171fe5ef |
[ty] Exclude nested global and nonlocal writes from class namespaces (#31143)
## Summary
Calling `update()` changes the value of `x` that we read in the class
body, but it doesn't create a `C.x` attribute.
```py
x = 0
class C:
def update():
global x
x = "changed"
update()
y = x
assert C.y == "changed"
assert "x" not in vars(C)
```
Since we don't track when `update` is called, we record a possible write
to `x` as soon as we see the function definition. Today we also treat
that write as a binding for `C.x`. If `C` inherits an attribute named
`x`, we can incorrectly include the global's type in the type of that
attribute.
We now remove these bindings for nested `global` and `nonlocal` writes
when we leave the class scope. Each read in the class body already has
its own snapshot of the bindings, so `y = x` still accounts for the
write.
Closes https://github.com/astral-sh/ty/issues/5024.
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
7b66e47507 |
[ty] Allow factory_boy subclasses to redeclare Meta and Params (#30939)
Main reports `incompatible-attribute-override` on both `Meta` declarations below. [factory_boy’s metaclass](https://github.com/FactoryBoy/factory_boy/blob/3.3.3/factory/base.py#L71-L90) removes `Meta` and `Params` before creating each factory, so there’s no inherited configuration class to override. ```python import factory class Base(factory.Factory): class Meta: abstract = True class Child(Base): class Meta: model = dict ``` ty now accepts both declarations and reports `missing-attribute` if you try to access `Base.Meta`, which raises `AttributeError` at runtime. Other nested classes still get the usual override checks. This applies to nested class declarations when the metaclass is `factory.base.FactoryMetaClass` or a subclass. This parallels our existing special-casing of Django inner Meta classes. `factory_boy` is a popular test-object-factory library used with Django, and copied its inner-Meta configuration pattern. Fixes astral-sh/ty#5123. |
||
|
|
99ab05df7e |
[ty] Fix stack overflow when checking generic return types with recursive aliases (#30934)
## Summary
This smaller example also crashes ty 0.0.110 (Python 3.12+).
```python
type A[T] = list[list[T]] | list[A[T]]
def g[T]() -> A[T]:
return []
def f[U]() -> A[U]:
return g()
```
At `return g()`, ty uses the expected return type `A[U]` to help infer
`T`. It first tries to rule out alternatives in the two unions that
can't overlap. One comparison pairs `list[list[T]]` from `A[T]` with
`list[A[U]]` from `A[U]`.
Because `list` is invariant, ty asks whether the element types `list[T]`
and `A[U]` can be equivalent. Expanding `A[U]` gives `list[list[U]] |
list[A[U]]`. For both alternatives to fit `list[T]`, the solver requires
`T` to equal both `list[U]` and `A[U]`.
Can those two requirements hold together? To find out, the solver
compares `list[U]` with `A[U]`. This repeats the previous comparison
with `U` in place of `T`. From here on, each check starts a new check of
exactly the same constraints.
```text
T = list[U] and T = A[U]
U = list[U] and U = A[U]
U = list[U] and U = A[U]
...
```
The solver only cached completed checks. Since each check waited for the
next one to finish, the cache stayed empty for those constraints and the
stack overflowed.
Fixes astral-sh/ty#5114.
## How the fix works
When the solver starts checking whether a set of constraints has a
solution, it records an in-progress entry (`None`) in the cache. If a
nested check reaches the same constraints with the same set of variables
it can infer, it provisionally assumes a solution exists. This breaks
the cycle and lets the solver check the remaining bounds.
An answer that depends on that assumption may be unsafe to reuse. For
example, suppose check `P` requires `Q` and one more condition, and `Q`
in turn requires `P`. The provisional success for `P` lets `Q` pass. If
the other condition then fails, a cached success for `Q` would be wrong.
To avoid this, the solver increments a counter each time it makes a
provisional assumption. If the counter changed during a check, the
solver removes that check's cache entry when it finishes.
## Test plan
The regression mdtest checks that `good` can return `g(x)` and that
`bad` gets an `invalid-explicit-return` diagnostic for `return g("s")`.
Verified that the mdtest overflows without the fix and passes with it.
The `ty_python_semantic` test suite and Clippy also passed locally.
|
||
|
|
56ad10d1a2 | [ty] Clarify the documentation for three removed rules (#31140) | ||
|
|
0e78666eb1 |
[ty] Preserve Never field types in generated dataclass methods (#31135)
## Summary ty accepted `Impossible(value=1)` for a dataclass with a required `value: Never` field, even though it inferred `Never` when reading the field. Looking up `__set__` on `Never` yields `Never`. Since ty treats `Never` as callable with arbitrary arguments, it inferred `Unknown` for the setter's value parameter. Here, we simply extend a special-case that was previously only active for dynamic types. This is something that's very common in ty: almost all special-cases for dynamic types apply to `Never` as well. fixes astral-sh/ty#5140 |
||
|
|
c36f4665cb |
[ty] Preserve attrs field converters when a validator is present (#31131)
## Summary attrs `field()` is overloaded. There are (valid) `field` calls that can lead to ambiguous overloads. In the example in astral-sh/ty#5134, this is caused by passing in a converter which takes an unspecialized `Attribute` argument (i.e. `Attribute[Unknown]`). With the change here, instead of "giving up", we combine/merge the result of ambiguous `field()` calls by merging their `Field` instances if the agree in metadata (`kw_only`, `init`, `converter`, ...). I believe I've seen cases of this in other dataclass-transformer libraries as well, which is why I added a test in `dataclass_transform` as well. Closes astral-sh/ty#5134 |
||
|
|
cb17cd8fd4 | [ty] Fix a panic on recursive enum value annotations (#30765) | ||
|
|
175421be18 |
[ty] Build fixed tuples directly from inferred element types (#31082)
## Summary Building fixed tuples directly saved 2.25% of instructions on `torch/sparse/_triton_ops_meta.py` and 0.41% on `torch/utils/hipify/cuda_to_hip_mappings.py`. These are two tuple-heavy files in the PyTorch benchmark. In a full PyTorch check, 50,482 of 51,149 visits to tuple inference took this path, skipping 162,260 lookups of already-inferred element types. In `tensor[i, :]`, for example, the subscript key is a tuple. Today, we infer each element, store its type, and then look it up again to build the tuple. For tuples that don't need unpacking or literal promotion, we can build the tuple directly from the types returned by inference. We can also iterate over the expected element types without collecting them into a temporary vector. <!-- ty-pinned-project-instructions:start --> <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef) | [PR instructions](https://github.com/astral-sh/ruff/commit/06675489b5f35d5b7f6936d2958b49a8a480c31d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,368,518,533.5 | 2,367,408,634.5 | -0.05% | -0.06% to -0.04% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,729,978,528 | 5,728,183,934.5 | -0.03% | -0.04% to -0.02% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 115,469,531,063.5 | 115,433,381,524.5 | -0.03% | -0.03% to -0.03% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,293,821,502 | 1,293,064,172 | -0.05% | -0.08% to -0.01% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,344,903,224.5 | 1,344,311,175 | -0.04% | -0.05% to -0.04% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 20,482,139,057.5 | 20,470,786,196 | -0.06% | -0.07% to -0.02% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,287,116,602 | 2,287,863,617 | +0.03% | +0.01% to +0.04% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 3,844,315,038.5 | 3,843,691,509.5 | -0.01% | -0.02% to -0.01% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 68,922,705,768 | 68,863,777,379 | -0.09% | -0.09% to -0.08% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,200,859,199 | 1,200,585,362.5 | -0.02% | -0.02% to -0.02% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 7,084,514,540.5 | 7,084,479,720 | 0.00% | -0.01% to +0.01% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,266,906,757 | 2,266,640,955 | -0.01% | -0.02% to -0.01% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 14,894,167,496.5 | 14,888,055,397 | -0.04% | -0.05% to -0.03% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 1,991,381,104 | 1,984,806,658 | -0.33% | -0.33% to -0.32% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 9,902,537,027 | 9,896,435,906 | -0.06% | -0.07% to -0.06% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 31,550,875,371.5 | 31,529,167,668.5 | -0.07% | -0.07% to -0.07% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 11,011,353,634.5 | 11,009,369,753 | -0.02% | -0.02% to -0.01% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,146,633,390.5 | 6,144,075,662 | -0.04% | -0.05% to -0.04% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,043,342,366 | 3,041,854,310.5 | -0.05% | -0.05% to -0.04% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,426,573,146 | 10,420,467,235.5 | -0.06% | -0.06% to -0.05% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,191,700,077 | 2,190,831,092.5 | -0.04% | -0.07% to -0.03% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,496,657,551 | 3,494,796,482.5 | -0.05% | -0.06% to -0.04% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 24,292,597,130 | 24,275,757,254.5 | -0.07% | -0.07% to -0.07% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,105,827,786 | 11,094,561,671 | -0.10% | -0.10% to -0.10% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,197,160,311.5 | 6,194,998,721.5 | -0.03% | -0.05% to -0.03% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 37,329,062,698 | 37,311,724,968.5 | -0.05% | -0.05% to -0.04% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,615,752,095.5 | 6,613,101,555 | -0.04% | -0.04% to -0.04% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 71,971,038,820.5 | 71,937,319,597 | -0.05% | -0.05% to -0.04% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.05 (+0.05%) | 8/16 | +0.19 | 0.00 (0.00%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | +0.15 (+0.08%) | 8/16 | −0.16 | 0.00 (0.00%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | +0.72 (+0.02%) | 9/16 | +0.12 | 0.00 (0.00%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | −0.33 (−0.47%) | 5/16 | +0.27 | 0.00 (0.00%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | +0.92 (+1.16%) | 16/16 | +1.07 | 0.00 (0.00%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | −0.18 (−0.03%) | 8/16 | +0.13 | 0.00 (0.00%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −0.32 (−0.24%) | 7/16 | +0.05 | 0.00 (0.00%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.47 (−0.25%) | 4/16 | +0.08 | 0.00 (0.00%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | +0.66 (+0.05%) | 8/16 | +0.18 | 0.00 (0.00%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | +0.14 (+0.17%) | 10/16 | +0.14 | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +0.85 (+0.39%) | 10/16 | +0.34 | 0.00 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.04 (+0.03%) | 8/16 | +0.05 | 0.00 (0.00%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −1.36 (−0.39%) | 7/16 | +0.02 | 0.00 (0.00%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | +0.84 (+0.83%) | 12/16 | +0.19 | 0.00 (0.00%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +1.16 (+0.43%) | 11/16 | +1.21 | 0.00 (0.00%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | +1.65 (+0.27%) | 11/16 | +0.04 | 0.00 (0.00%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | +0.43 (+0.15%) | 12/16 | +0.05 | 0.00 (0.00%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | +0.37 (+0.18%) | 8/16 | +0.05 | 0.00 (0.00%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.03 (−0.02%) | 8/16 | +0.13 | 0.00 (0.00%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −0.54 (−0.21%) | 7/16 | +0.22 | 0.00 (0.00%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | +0.07 (+0.07%) | 10/16 | +0.05 | 0.00 (0.00%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.29 (+0.20%) | 9/16 | +0.25 | 0.00 (0.00%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | +1.15 (+0.21%) | 10/16 | −0.11 | 0.00 (0.00%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +0.31 (+0.12%) | 10/16 | −0.15 | 0.00 (0.00%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | +0.40 (+0.32%) | 9/16 | −0.11 | 0.00 (0.00%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | +0.17 (+0.03%) | 8/16 | +0.15 | 0.00 (0.00%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | +0.24 (+0.12%) | 9/16 | −0.01 | 0.00 (0.00%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +0.27 (+0.02%) | 9/16 | +1.09 | 0.00 (0.00%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
680e277ff3 |
[ty] Skip wrapper overloads for built-in property reads (#31095)
## Summary SQLAlchemy uses `@property` 834 times. To read one of those properties, ty binds two synthesized overloads of `property.__get__` before calling the getter. For a built-in property with a nominal receiver and a valid owner, we can handle class access directly and call the getter through the usual binding path for instance access. This still specializes `Self` for subclasses. Custom descriptors and explicit `__get__` calls keep their existing behavior. If the getter call fails, we fall back to the original path so the diagnostic still describes the descriptor error. That can mean checking a failing getter twice. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.10% and the median was −0.07%. Weighting each project by its median instruction count on main gives a change of −0.13%. <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef) | [PR instructions](https://github.com/astral-sh/ruff/commit/14ad29da6faa7aa306092e8f0f99d484252a1708) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,374,189,022 | 2,373,054,042 | -0.05% | -0.05% to -0.04% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,727,900,235.5 | 5,719,738,818 | -0.14% | -0.14% to -0.14% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 115,486,991,410 | 115,135,467,058 | -0.30% | -0.30% to -0.30% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,296,146,299.5 | 1,295,287,010 | -0.07% | -0.08% to -0.05% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,342,440,234.5 | 1,341,765,526 | -0.05% | -0.07% to -0.04% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 20,483,314,937 | 20,462,912,318.5 | -0.11% | -0.11% to -0.08% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,285,124,225 | 2,280,785,836 | -0.19% | -0.21% to -0.16% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 3,843,673,250 | 3,843,259,205.5 | -0.01% | -0.02% to -0.01% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 68,910,772,632.5 | 68,879,629,864 | -0.05% | -0.05% to -0.04% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,204,799,001.5 | 1,203,894,338.5 | -0.07% | -0.08% to -0.07% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,143,951,024.5 | 7,114,369,692 | -0.41% | -0.42% to -0.40% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,255,947,225.5 | 2,255,904,792.5 | 0.00% | -0.02% to +0.01% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 14,956,127,824 | 14,927,181,120.5 | -0.19% | -0.20% to -0.19% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 1,988,503,007 | 1,987,357,381 | -0.06% | -0.07% to -0.05% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 9,884,095,990.5 | 9,877,581,354.5 | -0.07% | -0.07% to -0.06% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 31,571,430,630 | 31,530,941,966.5 | -0.13% | -0.13% to -0.12% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 10,990,504,739 | 10,980,340,661.5 | -0.09% | -0.10% to -0.09% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,153,877,312 | 6,148,238,654.5 | -0.09% | -0.10% to -0.08% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,046,009,519 | 3,040,427,481.5 | -0.18% | -0.19% to -0.18% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,427,505,606 | 10,421,122,601 | -0.06% | -0.07% to -0.06% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,193,389,575 | 2,192,275,048 | -0.05% | -0.06% to -0.05% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,498,149,095 | 3,496,048,196 | -0.06% | -0.06% to -0.06% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 24,287,905,364.5 | 24,271,959,845.5 | -0.07% | -0.07% to -0.05% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,105,238,488.5 | 11,103,011,431 | -0.02% | -0.03% to -0.02% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,194,943,230.5 | 6,190,726,173 | -0.07% | -0.07% to -0.06% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 37,341,153,785 | 37,320,589,604 | -0.05% | -0.06% to -0.05% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,619,998,599 | 6,614,966,137.5 | -0.08% | -0.08% to -0.07% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 71,968,718,219 | 71,940,449,902 | -0.04% | -0.04% to -0.04% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.15 (+0.14%) | 9/16 | +0.13 | −0.02 (−0.03%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | +0.46 (+0.25%) | 10/16 | −0.27 | −0.21 (−0.15%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | −6.56 (−0.21%) | 0/16 | −8.25 | −8.42 (−0.27%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | +0.34 (+0.50%) | 11/16 | −0.08 | −0.01 (−0.04%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | −0.12 (−0.15%) | 6/16 | +0.07 | −0.01 (−0.04%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +1.04 (+0.20%) | 9/16 | −0.51 | −0.45 (−0.10%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | +1.96 (+1.45%) | 13/16 | +2.03 | −0.08 (−0.10%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.36 (−0.18%) | 5/16 | +0.06 | −0.03 (−0.02%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | +2.73 (+0.19%) | 10/16 | −0.55 | −0.62 (−0.04%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | +1.59 (+1.84%) | 16/16 | +1.88 | −0.02 (−0.04%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +3.35 (+1.46%) | 10/16 | +1.21 | −0.57 (−0.31%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | −0.90 (−0.73%) | 6/16 | +0.03 | −0.02 (−0.03%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −1.09 (−0.31%) | 6/16 | −0.48 | −0.58 (−0.18%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.40 (−0.40%) | 6/16 | −0.02 | −0.04 (−0.08%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +2.05 (+0.75%) | 15/16 | +2.23 | −0.13 (−0.06%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | +0.83 (+0.13%) | 11/16 | +1.83 | −0.59 (−0.10%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | +0.39 (+0.14%) | 12/16 | −0.21 | −0.22 (−0.09%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | −0.03 (−0.01%) | 8/16 | +0.07 | −0.13 (−0.08%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.25 (−0.22%) | 6/16 | −0.14 | −0.11 (−0.15%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −0.32 (−0.12%) | 7/16 | −0.18 | −0.11 (−0.05%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.19 (−0.18%) | 4/16 | 0.00 | −0.03 (−0.04%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | −0.16 (−0.11%) | 7/16 | −0.19 | −0.05 (−0.05%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | +0.03 (+0.01%) | 8/16 | −0.49 | −0.33 (−0.07%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | −0.14 (−0.05%) | 6/16 | −0.05 | −0.04 (−0.02%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | −0.30 (−0.24%) | 7/16 | −0.08 | −0.04 (−0.04%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −0.12 (−0.02%) | 7/16 | −0.83 | −0.44 (−0.08%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −0.40 (−0.19%) | 5/16 | −0.03 | −0.10 (−0.06%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +1.88 (+0.13%) | 9/16 | −1.21 | −0.64 (−0.04%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
4d970500e5 |
[ty] Reserve keyword parameters only for variable-length positional unpacking (#31072)
## Summary
Before we match arguments to parameters, we look up each keyword and
collect the corresponding parameters in a hash set. We then look up the
same keywords again when we match them. We only need the first pass to
decide how many parameters an unpacked iterable can fill when we don’t
know its length.
```py
def f(a: str, b: float, c: int) -> None: ...
def example(args: list[str]) -> None:
f("x", 1.0, c=1)
f(*("x",), 1.0, c=1)
f(*args, 1.0, **{"c": 1})
```
In the first two calls, we know exactly how many positional arguments we
have. In the third, we need to reserve `c` for the keyword and leave `b`
for `1.0`. That leaves only `a` for `*args`.
We now scan for keywords the first time we encounter a variable-length
positional unpack. We mark the parameters supplied by named arguments or
by known required keys in a `**` unpack. Subsequent unpacks reuse those
marks. The marks fit in the same byte as the other per-parameter flags,
so we can drop the hash set and store the flags for up to 16 parameters
inline.
<!-- ty-pinned-project-instructions:start -->
<details>
<summary>Instruction counts by project</summary>
Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/ccb56b4000325f4cdc0a6e6159a433b5730d4923)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,368,479,896.5 | 2,367,610,664 | -0.04% | -0.04% to -0.03% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,729,833,960 | 5,726,334,746.5 | -0.06% | -0.07% to -0.05% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 115,384,545,174.5 | 115,238,617,777.5 | -0.13% | -0.13% to -0.13% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
(inconclusive) | 1,293,818,817.5 | 1,293,246,394 | -0.04% | -0.05% to
-0.02% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,344,886,091.5 | 1,344,641,916.5 | -0.02% | -0.02% to -0.02% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,479,945,301 | 20,457,529,543 | -0.10% | -0.13% to -0.09% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,287,133,455 | 2,288,188,169 | +0.05% | +0.03% to +0.06% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,844,353,431 | 3,839,906,931 | -0.11% | -0.12% to -0.11% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 68,877,167,705.5 | 68,834,005,704 | -0.06% | -0.07% to -0.06% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,200,890,654 | 1,200,580,705 | -0.03% | -0.03% to -0.02% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 7,084,025,802 | 7,079,659,221.5 | -0.07% | -0.09% to -0.05% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,250,900,891.5 | 2,249,291,209.5 | -0.07% | -0.08% to -0.07% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,930,399,836 | 14,937,092,609.5 | +0.04% | +0.04% to +0.06% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,991,327,459.5 | 1,989,336,359.5 | -0.10% | -0.11% to -0.09% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,902,504,670.5 | 9,898,590,134.5 | -0.04% | -0.04% to -0.04% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
(inconclusive) | 31,335,072,518 | 31,333,414,274.5 | -0.01% | -0.01% to
0.00% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 11,011,184,254 | 10,993,372,724.5 | -0.16% | -0.16% to -0.16% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,146,337,718.5 | 6,142,931,887.5 | -0.05% | -0.06% to -0.05% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 3,043,408,338 | 3,042,647,240 | -0.03% | -0.03% to -0.01% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,426,339,312 | 10,420,991,328.5 | -0.05% | -0.05% to -0.05% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,191,700,226.5 | 2,190,885,467 | -0.03% | -0.05% to -0.02% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,496,723,735.5 | 3,495,240,891.5 | -0.04% | -0.05% to -0.04% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 24,292,983,095 | 24,277,778,633.5 | -0.06% | -0.07% to -0.05% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 11,105,800,255.5 | 11,097,988,065 | -0.07% | -0.07% to -0.07% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,197,741,660.5 | 6,193,645,820 | -0.07% | -0.07% to -0.06% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 37,328,410,879.5 | 37,257,880,216 | -0.19% | -0.19% to -0.19% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,615,786,483.5 | 6,612,039,520 | -0.06% | -0.06% to -0.05% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 71,970,756,171.5 | 71,914,983,141 | -0.08% | -0.08% to -0.08% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median paired change in MiB. We ran 16 pairs with
default parallelism and four with one worker. The last column estimates
retained query storage from two separate single-worker pairs. It
excludes some allocations.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Estimated query storage (MiB) |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −0.40 (−0.37%) | 6/16 | +0.22 | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.78 (−0.43%) | 6/16 | −0.03 | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| +0.25 (+0.01%) | 8/16 | +0.05 | 0.00 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.79 (−1.09%) | 4/16 | +0.13 | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| +0.01 (+0.01%) | 9/16 | −0.04 | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +1.53 (+0.30%) | 10/16 | −0.13 | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.31 (−0.23%) | 8/16 | −0.11 | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.40 (−0.21%) | 6/16 | +0.02 | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +0.85 (+0.06%) | 9/16 | +0.35 | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| −0.07 (−0.08%) | 8/16 | +0.07 | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −0.27 (−0.13%) | 8/16 | +0.11 | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| +0.21 (+0.18%) | 9/16 | −0.15 | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −1.12 (−0.32%) | 6/16 | +0.13 | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.05 (+0.05%) | 8/16 | −0.08 | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.05 (−0.02%) | 8/16 | +0.19 | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −0.08 (−0.01%) | 8/16 | −0.07 | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.04 (−0.02%) | 8/16 | −0.20 | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.04 (−0.02%) | 7/16 | −0.07 | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.77 (−0.67%) | 4/16 | +0.15 | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| +0.09 (+0.04%) | 9/16 | +0.13 | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.14 (+0.13%) | 10/16 | −0.12 | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.05 (−0.04%) | 8/16 | +0.57 | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| +0.03 (+0.01%) | 8/16 | −0.01 | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| +0.03 (+0.01%) | 8/16 | +0.20 | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +0.11 (+0.09%) | 9/16 | +0.07 | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −0.42 (−0.07%) | 7/16 | −0.06 | 0.00 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.45 (+0.22%) | 10/16 | −0.12 | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −1.03 (−0.07%) | 6/16 | −0.14 | 0.00 (0.00%) |
</details>
<!-- ty-pinned-project-instructions:end -->
|
||
|
|
d9066db969 |
[ty] Filter TypedDict.get overloads by key and arity (#30868)
## Summary
We generate overloads for every key in a `TypedDict`. For a call like
`row.get("name")`, we bind overloads for other keys and for calls with a
default, even though none of them can match.
We now keep the overloads for the literal key and the general string
fallback. If the call supplies a default, as in `row.get("name", "")`,
we filter by argument count alone. Overloads for other keys can affect
how we infer the default. We only do this for the receiver’s generated
`get` method, including in unions. When collecting expected types for
the editor, we keep every key for the matching argument count.
<!-- ty-pinned-project-instructions:start -->
<details>
<summary>Instruction counts by project</summary>
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/8f0189e0e975334474efb938eafc48f22855aadb)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/fbae31ad759a4f55c210db8c3c8863e46d8b4312)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
(inconclusive) | 2,519,111,672.5 | 2,518,918,211 | 0.00% | -0.01% to
0.00% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 6,094,007,668 | 6,011,392,165 | -1.36% | -1.36% to -1.35% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 122,816,187,227 | 122,733,427,508.5 | -0.07% | -0.07% to -0.07% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,375,645,850 | 1,375,541,367 | -0.01% | -0.01% to -0.01% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,442,289,861.5 | 1,441,748,711 | -0.04% | -0.05% to -0.02% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 21,652,150,340.5 | 21,636,387,828 | -0.07% | -0.08% to -0.07% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,485,289,935 | 2,486,032,483 | +0.03% | +0.02% to +0.03% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
(inconclusive) | 4,103,725,687 | 4,103,609,961 | 0.00% | -0.01% to 0.00%
|
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 72,339,963,976 | 72,327,253,562.5 | -0.02% | -0.02% to -0.02% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
(inconclusive) | 1,296,083,932.5 | 1,296,174,249 | +0.01% | 0.00% to
+0.03% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 7,574,668,335.5 | 7,576,748,449 | +0.03% | -0.01% to
+0.06% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,414,692,860 | 2,402,931,770.5 | -0.49% | -0.49% to -0.48% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 15,854,622,386.5 | 15,853,197,849 | -0.01% | -0.02% to -0.01% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
(inconclusive) | 2,123,470,076.5 | 2,123,815,497.5 | +0.02% | +0.01% to
+0.02% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 10,463,332,001.5 | 10,464,327,847.5 | +0.01% | +0.01% to +0.01% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
(inconclusive) | 33,063,769,364 | 33,065,477,178 | +0.01% | 0.00% to
+0.01% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 11,756,489,946 | 11,726,196,046 | -0.26% | -0.27% to -0.25% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,570,369,814 | 6,571,644,807 | +0.02% | +0.02% to +0.02% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
(inconclusive) | 3,236,347,027.5 | 3,236,389,275.5 | 0.00% | 0.00% to
0.00% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
(inconclusive) | 10,947,372,783.5 | 10,946,921,143.5 | 0.00% | -0.01% to
0.00% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,340,188,910.5 | 2,340,711,330 | +0.02% | +0.01% to +0.02% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,706,837,146 | 3,707,175,101.5 | +0.01% | +0.01% to +0.02% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 25,569,257,706.5 | 25,554,635,732 | -0.06% | -0.06% to -0.06% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 11,666,350,193.5 | 11,667,912,989 | +0.01% | +0.01% to +0.02% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,464,591,580.5 | 6,389,545,397 | -1.16% | -1.17% to -1.16% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 39,256,420,896.5 | 39,241,855,598 | -0.04% | -0.04% to -0.04% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 7,067,849,098.5 | 7,068,761,627 | +0.01% | 0.00% to +0.02% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 75,643,415,480 | 75,634,629,479.5 | -0.01% | -0.01% to -0.01% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median paired change in MiB. We ran 16 pairs with
default parallelism and four with one worker. The last column estimates
retained query storage from two separate single-worker pairs. It
excludes some allocations.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Estimated query storage (MiB) |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| +0.92 (+0.83%) | 12/16 | +0.08 | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| −0.38 (−0.21%) | 7/16 | −0.09 | −0.14 (−0.10%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.45 (−0.01%) | 8/16 | −0.19 | −0.46 (−0.01%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +3.04 (+4.24%) | 16/16 | +3.04 | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.13 (−0.16%) | 5/16 | −0.13 | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| −1.72 (−0.33%) | 7/16 | −0.45 | −0.03 (−0.01%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.06 (−0.04%) | 8/16 | +0.04 | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.02 (−0.01%) | 8/16 | +0.01 | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +4.61 (+0.32%) | 11/16 | +2.80 | −0.04 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +2.63 (+3.01%) | 16/16 | +3.00 | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +0.26 (+0.11%) | 8/16 | +2.19 | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.71 (−0.58%) | 4/16 | −0.14 | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| +1.32 (+0.37%) | 10/16 | +0.25 | −0.01 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.26 (+0.25%) | 9/16 | −0.19 | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.42 (−0.15%) | 6/16 | +0.08 | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| +2.88 (+0.46%) | 10/16 | −0.20 | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.18 (−0.06%) | 5/16 | −0.10 | −0.32 (−0.14%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| +0.71 (+0.33%) | 11/16 | −0.48 | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.75 (−0.64%) | 2/16 | −1.15 | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| +0.26 (+0.10%) | 9/16 | +0.27 | −0.01 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| −0.47 (−0.43%) | 5/16 | −0.08 | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| +0.64 (+0.45%) | 11/16 | +0.13 | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.45 (−0.08%) | 7/16 | +0.23 | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 0.00 (0.00%) | 8/16 | +0.37 | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| −3.05 (−2.40%) | 0/16 | −1.72 | −0.22 (−0.29%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| +2.37 (+0.41%) | 13/16 | +2.22 | 0.00 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.25 (+0.12%) | 9/16 | +0.19 | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −2.38 (−0.16%) | 6/16 | −0.30 | −0.13 (−0.01%) |
</details>
<!-- ty-pinned-project-instructions:end -->
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
8f36bfa294 |
[ty] Share metaclass instance member lookups across classes (#31087)
## Summary If `A` and `B` both use `Meta`, looking up `a.field` and `b.field` checks the same instance storage on `Meta` twice. This also happens for ordinary classes whose metaclass is `type`, even when the lookup finds nothing. We now cache that raw lookup by program, specialized metaclass and name. A dedicated key keeps Salsa from reserving space for this result on every ordinary member lookup. Each class still resolves its own declarations and inherited attributes, and descriptors still bind to the original receiver. If a lookup encounters a cycle, the caller computes the result directly. <!-- ty-pinned-project-instructions:start --> Measured 22 of 28 projects. <details> <summary>Instruction counts by project</summary> The benchmark build used the same source tree as the linked commit applied to main. Both builds use the linked main commit, with this PR applied to the second. Counts are medians of four single-worker Cachegrind runs on Linux (x86-64). Change is the median of four paired percentages. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/faf3d689c3eb6898c8fafbf3eea876902ca748d8) | [PR instructions](https://github.com/astral-sh/ruff/commit/82adb12cf5f4c08413ad7358b638bc9732980fbc) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,367,450,164 | 2,363,449,924 | -0.17% | -0.18% to -0.17% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,702,271,180.5 | 5,673,527,729.5 | -0.50% | -0.52% to -0.49% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,291,001,547 | 1,288,735,938 | -0.16% | -0.22% to -0.15% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,341,221,431.5 | 1,334,951,307 | -0.47% | -0.48% to -0.46% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 20,319,673,775.5 | 20,253,275,601 | -0.33% | -0.34% to -0.32% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,276,356,595.5 | 2,272,804,890 | -0.15% | -0.16% to -0.15% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 3,777,249,308.5 | 3,770,285,483.5 | -0.18% | -0.19% to -0.18% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,199,054,791 | 1,195,133,920 | -0.33% | -0.33% to -0.33% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,048,504,189.5 | 7,031,875,156 | -0.24% | -0.25% to -0.22% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,248,748,623 | 2,244,581,501 | -0.19% | -0.19% to -0.18% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 14,878,182,814.5 | 14,811,847,140.5 | -0.45% | -0.45% to -0.44% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 1,984,590,128 | 1,976,527,594.5 | -0.40% | -0.41% to -0.39% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 9,885,927,252 | 9,807,159,389.5 | -0.80% | -0.80% to -0.80% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 10,909,349,129 | 10,859,529,371 | -0.46% | -0.46% to -0.45% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,124,963,560.5 | 6,103,232,868 | -0.35% | -0.36% to -0.35% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,036,430,304.5 | 3,025,262,792.5 | -0.37% | -0.37% to -0.36% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,407,114,559 | 10,376,571,338 | -0.29% | -0.29% to -0.29% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,197,013,209 | 2,185,635,877 | -0.52% | -0.53% to -0.51% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,495,391,746 | 3,480,986,845.5 | -0.41% | -0.44% to -0.41% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 24,109,326,868.5 | 24,053,166,489.5 | -0.23% | -0.24% to -0.23% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,094,784,214 | 11,067,662,697.5 | -0.24% | -0.25% to -0.24% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,593,766,878.5 | 6,562,639,275 | -0.47% | -0.48% to -0.46% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.47 (+0.42%) | 11/16 | +0.74 | +0.09 (+0.13%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | −0.17 (−0.09%) | 7/16 | +0.41 | +0.22 (+0.16%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | +0.73 (+1.06%) | 11/16 | +0.25 | +0.05 (+0.13%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | +0.17 (+0.21%) | 11/16 | +0.12 | +0.06 (+0.16%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +0.21 (+0.04%) | 8/16 | +0.97 | +0.32 (+0.07%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −0.43 (−0.32%) | 7/16 | +0.23 | +0.01 (+0.02%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.28 (−0.14%) | 5/16 | +0.16 | +0.05 (+0.03%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | +0.13 (+0.15%) | 9/16 | +0.11 | +0.03 (+0.08%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +2.46 (+1.12%) | 11/16 | −0.17 | +0.01 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.25 (+0.21%) | 9/16 | +0.38 | +0.05 (+0.07%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | +2.55 (+0.74%) | 11/16 | +1.11 | +0.51 (+0.16%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | +0.54 (+0.54%) | 11/16 | +0.25 | +0.11 (+0.19%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +1.23 (+0.46%) | 12/16 | +1.11 | +0.37 (+0.16%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | −0.71 (−0.25%) | 6/16 | +0.35 | −0.06 (−0.03%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | −0.37 (−0.18%) | 8/16 | +0.60 | +0.19 (+0.12%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | +0.08 (+0.07%) | 9/16 | +0.55 | +0.18 (+0.24%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | +1.00 (+0.39%) | 12/16 | +0.50 | +0.50 (+0.23%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | +0.63 (+0.59%) | 14/16 | +0.46 | +0.26 (+0.40%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.14 (+0.10%) | 12/16 | +0.36 | +0.31 (+0.32%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | +1.21 (+0.22%) | 10/16 | +0.30 | −0.12 (−0.02%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +0.15 (+0.06%) | 10/16 | +0.34 | +0.04 (+0.02%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | +1.29 (+0.63%) | 13/16 | +0.51 | +0.32 (+0.19%) | </details> <!-- ty-pinned-project-instructions:end --> --------- Co-authored-by: Charlie Marsh <charliemarsh@openai.com> |
||
|
|
c94361d0fb |
[ty] Check for protocol methods before binding descriptors (#31062)
## Summary
Before we compare signatures, we check that a type has every member a
protocol requires. If we can’t find a member on the class, we try
ordinary attribute lookup. For a method like `flush`, that can send us
through `__getattr__` only to reject the match during the full protocol
check.
```py
from typing import Callable, Protocol
class Flushable(Protocol):
def flush(self) -> None: ...
class Stream:
def __getattr__(self, name: str) -> Callable[[], None]:
return lambda: None
def as_flushable(stream: Stream) -> Flushable:
stream.flush() # OK via __getattr__
return stream # Error: Stream has no flush method on the class
```
When checking an instance or a literal against a protocol, we now look
for each required instance method directly on the class and its bases.
If the method is missing, we can rule out the match immediately. If it’s
present, we wait until we compare signatures to bind the descriptor to
the instance.
We keep the existing lookup for properties, `__call__`, and type
variables whose bound differs from the receiver. When reporting a
mismatch, we still run the full comparison so we can explain which
member failed.
<!-- ty-pinned-project-instructions:start -->
<details>
<summary>Instruction counts by project</summary>
Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/cbf2b94ef67e44a554643efbee653a2f62fcaab4)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,374,054,149 | 2,369,664,851.5 | -0.18% | -0.19% to -0.18% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,727,940,043 | 5,720,964,575.5 | -0.12% | -0.12% to -0.12% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 115,357,844,848 | 115,311,395,236 | -0.04% | -0.04% to -0.04% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,296,153,370 | 1,294,140,041.5 | -0.15% | -0.16% to -0.14% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,342,428,234.5 | 1,338,256,563 | -0.31% | -0.31% to -0.31% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,475,851,688 | 20,429,562,706.5 | -0.22% | -0.26% to -0.22% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| 2,286,674,614 | 2,276,047,590 | -0.47% | -0.47% to -0.46% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,847,652,778.5 | 3,835,709,011.5 | -0.31% | -0.32% to -0.31% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 68,868,161,415.5 | 68,824,459,896.5 | -0.06% | -0.07% to -0.06% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,204,068,000.5 | 1,200,591,585.5 | -0.29% | -0.32% to -0.27% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| 7,050,134,010 | 7,028,928,111.5 | -0.31% | -0.32% to -0.28% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,257,219,352 | 2,255,410,211.5 | -0.08% | -0.09% to -0.07% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,938,584,834 | 14,907,442,207 | -0.21% | -0.21% to -0.21% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,988,406,720 | 1,982,131,281.5 | -0.32% | -0.32% to -0.31% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,883,958,277 | 9,875,044,595.5 | -0.09% | -0.09% to -0.09% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 31,541,954,434.5 | 31,519,083,871.5 | -0.07% | -0.08% to -0.06% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 10,999,042,466.5 | 10,993,305,651.5 | -0.05% | -0.05% to -0.05% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,147,133,529.5 | 6,138,148,301.5 | -0.15% | -0.15% to -0.14% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 3,043,919,894.5 | 3,038,283,869 | -0.19% | -0.19% to -0.18% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,422,250,307.5 | 10,410,169,036 | -0.12% | -0.12% to -0.11% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,193,434,147.5 | 2,190,635,547 | -0.13% | -0.16% to -0.13% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,494,567,648.5 | 3,491,399,957.5 | -0.09% | -0.09% to -0.09% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 24,290,144,672 | 24,245,105,803.5 | -0.18% | -0.19% to -0.18% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 11,097,575,784 | 11,071,255,983 | -0.24% | -0.24% to -0.23% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,198,905,344 | 6,194,005,613.5 | -0.08% | -0.10% to -0.07% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 37,328,178,237.5 | 37,162,837,057 | -0.44% | -0.45% to -0.44% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,620,219,433.5 | 6,610,939,976.5 | -0.14% | -0.14% to -0.14% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 71,876,033,114.5 | 71,816,707,192.5 | -0.08% | -0.08% to -0.08% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median paired change in MiB. We ran 16 pairs with
default parallelism and four with one worker. The last column estimates
retained query storage from two separate single-worker pairs. It
excludes some allocations.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Estimated query storage (MiB) |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| +0.09 (+0.08%) | 8/16 | +0.01 | −0.11 (−0.17%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.53 (+0.29%) | 10/16 | −0.16 | −0.21 (−0.15%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| −0.18 (−0.01%) | 8/16 | −1.39 | −1.70 (−0.05%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +0.24 (+0.35%) | 8/16 | 0.00 | −0.06 (−0.18%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.04 (−0.05%) | 6/16 | +0.02 | −0.09 (−0.24%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| −0.84 (−0.17%) | 8/16 | −0.81 | −1.44 (−0.31%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −0.25 (−0.19%) | 7/16 | +0.01 | −0.29 (−0.34%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.10 (−0.05%) | 7/16 | −0.06 | −0.27 (−0.19%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −2.24 (−0.16%) | 6/16 | −1.04 | −1.71 (−0.12%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.05 (+0.06%) | 9/16 | +0.05 | −0.08 (−0.18%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −1.56 (−0.68%) | 7/16 | −0.07 | −0.61 (−0.35%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.86 (−0.71%) | 6/16 | +0.18 | −0.04 (−0.05%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.58 (−0.17%) | 7/16 | −0.24 | −0.81 (−0.26%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.10 (−0.09%) | 8/16 | 0.00 | −0.17 (−0.28%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| +0.40 (+0.15%) | 11/16 | −0.07 | −0.25 (−0.11%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −0.93 (−0.15%) | 8/16 | −0.35 | −0.80 (−0.14%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.70 (−0.25%) | 5/16 | −0.03 | −0.24 (−0.10%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.56 (−0.27%) | 4/16 | +0.01 | −0.25 (−0.16%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.16 (−0.14%) | 8/16 | −0.05 | −0.18 (−0.24%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| −0.43 (−0.17%) | 5/16 | −0.31 | −0.36 (−0.16%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| −0.26 (−0.25%) | 6/16 | −0.08 | −0.08 (−0.13%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.04 (−0.03%) | 6/16 | +0.20 | −0.13 (−0.14%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −3.00 (−0.55%) | 4/16 | −1.01 | −1.60 (−0.33%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| −0.12 (−0.05%) | 8/16 | −0.64 | −0.76 (−0.35%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +2.11 (+1.70%) | 15/16 | +2.57 | −0.06 (−0.07%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −3.11 (−0.56%) | 0/16 | −3.10 | −4.49 (−0.83%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.03 (+0.02%) | 8/16 | −0.37 | −0.24 (−0.14%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| +0.30 (+0.02%) | 8/16 | −1.32 | −1.79 (−0.13%) |
</details>
<!-- ty-pinned-project-instructions:end -->
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
ee4f745248 |
[ty] Only probe dictionary fallbacks for a single TypedDict candidate (#31045)
## Summary
When we check a dictionary literal against a union, we try inferring it
against each non-`TypedDict` member until we find one that accepts it.
We use the result to decide whether to report errors for the fields of a
single `TypedDict`.
```py
from collections.abc import Mapping
from typing import TypedDict
class Person(TypedDict):
name: str
person: Person | Mapping[str, str] = {"nickname": "Ali"} # OK via Mapping
data: None | dict[str, list[int]] = {"items": [1, 2]}
```
For `person`, the mapping accepts the literal, so we shouldn’t report
that `nickname` is an unknown key on `Person`. For `data`, there are no
`TypedDict` fields to check. Looking for a fallback just makes us infer
the nested list again.
We now collect the `TypedDict` candidates first and only look for a
fallback when there’s exactly one. With multiple candidates, we still
check the literal against the candidate `TypedDict`s. Ordinary
dictionary inference still uses the original union.
This adapts @sharkdp’s #30121 to the current expected-type API.
Only the microbenchmark has changed since the measurements below.
<!-- ty-pinned-project-instructions:start -->
<details>
<summary>Instruction counts by project</summary>
Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/754ce140212f718f694865de7d4e32eb2646b4c8)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/d300993f5029e2dae1cbde2667ebfb4cbeed842f)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
(inconclusive) | 2,378,457,247 | 2,378,465,415.5 | 0.00% | -0.01% to
+0.02% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,754,622,302.5 | 5,752,311,613 | -0.04% | -0.04% to -0.04% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 115,632,753,285.5 | 115,128,244,472 | -0.44% | -0.44% to -0.44% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| 1,296,948,377 | 1,296,833,291 | -0.01% | -0.01% to 0.00% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
(inconclusive) | 1,344,765,005 | 1,344,641,480.5 | -0.01% | -0.02% to
0.00% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,652,006,536 | 20,649,536,476 | -0.01% | -0.02% to -0.01% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
(inconclusive) | 2,289,813,895 | 2,289,881,778.5 | 0.00% | -0.01% to
+0.01% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 3,848,629,577 | 3,844,048,562.5 | -0.12% | -0.12% to -0.12% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 69,326,834,406.5 | 69,280,578,808 | -0.07% | -0.07% to -0.06% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| 1,195,979,470.5 | 1,195,238,101.5 | -0.06% | -0.08% to -0.04% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 7,156,037,403 | 7,156,231,894.5 | 0.00% | -0.03% to
+0.06% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| 2,272,864,782 | 2,271,566,073.5 | -0.05% | -0.07% to -0.04% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,988,865,752 | 14,980,333,011.5 | -0.05% | -0.06% to -0.05% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,992,639,957.5 | 1,992,148,589.5 | -0.02% | -0.03% to -0.02% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,929,627,715.5 | 9,925,076,521 | -0.05% | -0.05% to -0.05% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 31,681,132,864.5 | 31,658,452,984.5 | -0.07% | -0.07% to -0.07% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| 11,094,959,238.5 | 11,029,706,034.5 | -0.59% | -0.59% to -0.58% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,157,483,229.5 | 6,156,584,973 | -0.01% | -0.02% to -0.01% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 3,053,359,769 | 3,052,516,650.5 | -0.03% | -0.03% to -0.02% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,454,729,011.5 | 10,451,991,475 | -0.02% | -0.03% to -0.02% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
(inconclusive) | 2,195,745,393 | 2,195,424,560 | -0.01% | -0.04% to
+0.02% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,504,390,525 | 3,503,262,728 | -0.03% | -0.04% to -0.02% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 24,361,054,548.5 | 24,292,409,806.5 | -0.28% | -0.29% to -0.27% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 11,129,745,470.5 | 11,113,015,722 | -0.15% | -0.15% to -0.14% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| 6,220,153,501 | 6,214,401,666.5 | -0.09% | -0.10% to -0.09% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 37,561,559,267.5 | 37,404,736,874 | -0.42% | -0.42% to -0.42% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,628,730,899 | 6,592,871,888.5 | -0.54% | -0.54% to -0.53% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 72,300,830,900 | 72,135,761,388.5 | -0.23% | -0.23% to -0.23% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median paired change in MiB. We ran 16 pairs with
default parallelism and four with one worker. The last column estimates
retained query storage from two separate single-worker pairs. It
excludes some allocations.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Estimated query storage (MiB) |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| −0.14 (−0.13%) | 6/16 | −0.27 | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.07 (+0.04%) | 9/16 | −0.09 | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| +1.04 (+0.03%) | 10/16 | +0.26 | −0.07 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| −0.30 (−0.43%) | 6/16 | −0.16 | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.26 (−0.33%) | 5/16 | +0.04 | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| +1.29 (+0.25%) | 9/16 | +0.12 | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| +0.57 (+0.43%) | 9/16 | +0.10 | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| 0.00 (0.00%) | 7/16 | −0.23 | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| +2.05 (+0.15%) | 9/16 | −0.87 | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.08 (+0.10%) | 8/16 | −0.10 | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| +6.98 (+3.16%) | 12/16 | +0.07 | 0.00 (0.00%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.81 (−0.66%) | 6/16 | −0.02 | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| +1.08 (+0.31%) | 9/16 | +0.19 | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| −0.25 (−0.24%) | 8/16 | 0.00 | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| −0.21 (−0.08%) | 7/16 | −0.03 | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −1.58 (−0.26%) | 7/16 | −0.20 | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| +1.16 (+0.41%) | 10/16 | −0.04 | −0.02 (−0.01%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| −0.65 (−0.31%) | 5/16 | +0.07 | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| −0.09 (−0.08%) | 7/16 | +0.12 | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| +0.25 (+0.10%) | 9/16 | −0.10 | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.12 (+0.11%) | 8/16 | +0.09 | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| −0.21 (−0.15%) | 7/16 | +0.15 | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.07 (−0.01%) | 8/16 | −0.24 | −0.04 (−0.01%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| +0.06 (+0.02%) | 9/16 | −0.01 | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +0.23 (+0.19%) | 8/16 | +0.05 | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| +0.02 (0.00%) | 8/16 | −0.18 | −0.02 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| +0.03 (+0.01%) | 9/16 | −0.10 | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| −0.91 (−0.06%) | 8/16 | −0.14 | −0.01 (0.00%) |
</details>
<!-- ty-pinned-project-instructions:end -->
|
||
|
|
f625661976 |
[ty] Infer ordinary arguments to dynamic calls without binding a signature (#31080)
## Summary
In SymPy’s matrix tests, `factory` is unannotated, so both `factory` and
`matrix.getitem` have type `Unknown`.
```py
def test_getitem(factory):
matrix = factory([[1, 2]]) # Unknown
matrix.getitem(0, 1) # Unknown
```
For each call, we build a `(*args, **kwargs)` signature and match the
arguments to it. When the callee is exactly `Any` or `Unknown`, that
signature accepts every argument, gives us no expected types, and
returns the callee’s type.
We now skip binding and infer the arguments directly, in source order.
We still report errors inside argument expressions. We keep the full
call path to validate unpacking, check `TypedDict` keys, and infer the
element types of unannotated collections from method calls.
<!-- ty-pinned-project-instructions:start -->
<details>
<summary>Instruction counts by project</summary>
Both builds use the linked main commit, with this PR applied to the
second. Counts are medians of four single-worker Cachegrind runs on
Linux (x86-64). Change is the median of four paired percentages. We
marked a result inconclusive when the pairs disagreed in direction or
the change was within the variation between runs of either build.
| Project | [Base
instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef)
| [PR
instructions](https://github.com/astral-sh/ruff/commit/830a01d914f2ec31d2f053d17b9c83d5fb165dae)
| Change | Paired range |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| 2,368,491,921.5 | 2,367,993,307 | -0.02% | -0.03% to -0.01% |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| 5,730,155,934 | 5,728,745,321 | -0.02% | -0.03% to -0.02% |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| 115,523,278,810 | 115,463,159,581.5 | -0.05% | -0.05% to -0.05% |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
(inconclusive) | 1,293,829,246 | 1,293,518,293.5 | -0.02% | -0.05% to
+0.01% |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| 1,344,918,605.5 | 1,344,674,691 | -0.02% | -0.02% to -0.01% |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| 20,478,731,646.5 | 20,461,716,637.5 | -0.08% | -0.10% to -0.07% |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
(inconclusive) | 2,287,293,259.5 | 2,287,377,582 | 0.00% | -0.02% to
+0.01% |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
(inconclusive) | 3,844,416,362.5 | 3,844,068,150.5 | -0.01% | -0.02% to
0.00% |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| 68,912,198,342 | 68,610,091,415 | -0.44% | -0.44% to -0.43% |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
(inconclusive) | 1,200,820,557.5 | 1,200,691,434 | -0.01% | -0.02% to
0.00% |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
(inconclusive) | 7,084,354,369.5 | 7,083,059,761.5 | -0.02% | -0.03% to
0.00% |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
(inconclusive) | 2,250,882,267 | 2,250,544,189.5 | -0.02% | -0.02% to
0.00% |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| 14,930,282,065.5 | 14,905,763,826 | -0.16% | -0.18% to -0.16% |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| 1,991,378,658 | 1,991,024,532.5 | -0.02% | -0.02% to -0.02% |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| 9,902,590,260 | 9,850,518,959.5 | -0.52% | -0.53% to -0.52% |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| 31,552,750,181 | 31,414,089,337.5 | -0.44% | -0.44% to -0.43% |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
(inconclusive) | 11,010,946,167 | 11,010,575,111.5 | 0.00% | -0.01% to
0.00% |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| 6,146,250,396.5 | 6,136,099,531.5 | -0.17% | -0.18% to -0.16% |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| 3,043,446,538.5 | 3,042,623,172.5 | -0.03% | -0.03% to -0.02% |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| 10,426,275,310.5 | 10,394,074,896.5 | -0.31% | -0.31% to -0.31% |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| 2,191,690,971.5 | 2,179,151,119 | -0.57% | -0.59% to -0.56% |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| 3,496,740,441.5 | 3,481,784,996 | -0.43% | -0.44% to -0.42% |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| 24,291,853,188 | 24,185,477,644 | -0.44% | -0.45% to -0.43% |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| 11,105,761,402.5 | 10,957,540,880 | -1.34% | -1.34% to -1.33% |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
(inconclusive) | 6,197,536,312.5 | 6,197,195,651.5 | -0.01% | -0.02% to
0.00% |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| 37,338,768,642 | 37,143,324,432 | -0.52% | -0.53% to -0.52% |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| 6,615,485,531.5 | 6,589,425,084.5 | -0.39% | -0.40% to -0.39% |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| 71,881,941,000 | 70,887,815,947 | -1.38% | -1.39% to -1.38% |
</details>
<details>
<summary>Memory by project</summary>
Peak RSS is the median paired change in MiB. We ran 16 pairs with
default parallelism and four with one worker. The last column estimates
retained query storage from two separate single-worker pairs. It
excludes some allocations.
| Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one
worker (MiB) | Estimated query storage (MiB) |
| --- | ---: | ---: | ---: | ---: |
|
[Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7)
| +0.04 (+0.03%) | 8/16 | +0.13 | 0.00 (0.00%) |
|
[discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0)
| +0.48 (+0.26%) | 9/16 | +0.18 | 0.00 (0.00%) |
| [Home
Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b)
| +0.88 (+0.03%) | 9/16 | +0.04 | 0.00 (0.00%) |
|
[isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab)
| +0.24 (+0.34%) | 10/16 | +0.04 | 0.00 (0.00%) |
|
[Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044)
| −0.03 (−0.04%) | 6/16 | +0.05 | 0.00 (0.00%) |
|
[pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54)
| −0.12 (−0.02%) | 8/16 | +0.22 | 0.00 (0.00%) |
|
[pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6)
| −1.06 (−0.79%) | 5/16 | −0.05 | 0.00 (0.00%) |
|
[Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03)
| −0.23 (−0.12%) | 5/16 | −0.22 | 0.00 (0.00%) |
|
[PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f)
| −4.79 (−0.34%) | 5/16 | +0.08 | 0.00 (0.00%) |
|
[HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254)
| +0.18 (+0.21%) | 10/16 | −0.09 | 0.00 (0.00%) |
|
[NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410)
| −1.26 (−0.56%) | 6/16 | +0.26 | −0.02 (−0.01%) |
|
[FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4)
| −0.14 (−0.12%) | 6/16 | +0.09 | 0.00 (0.00%) |
|
[SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b)
| −0.98 (−0.28%) | 6/16 | +0.13 | 0.00 (0.00%) |
|
[Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f)
| +0.24 (+0.24%) | 9/16 | +0.01 | 0.00 (0.00%) |
|
[Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02)
| +0.54 (+0.20%) | 9/16 | −0.05 | 0.00 (0.00%) |
|
[SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a)
| −1.94 (−0.31%) | 5/16 | 0.00 | 0.00 (0.00%) |
| [OpenAI Python
SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312)
| −0.31 (−0.11%) | 7/16 | +0.08 | 0.00 (0.00%) |
|
[pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b)
| +1.19 (+0.56%) | 12/16 | −0.21 | 0.00 (0.00%) |
|
[aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43)
| +0.29 (+0.26%) | 10/16 | +0.26 | 0.00 (0.00%) |
|
[Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2)
| +0.08 (+0.03%) | 8/16 | +0.23 | 0.00 (0.00%) |
|
[botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78)
| +0.09 (+0.09%) | 8/16 | +0.01 | 0.00 (0.00%) |
|
[Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1)
| +0.29 (+0.21%) | 12/16 | +0.14 | 0.00 (0.00%) |
|
[Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3)
| −0.02 (0.00%) | 8/16 | −0.02 | 0.00 (0.00%) |
|
[NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1)
| +0.06 (+0.02%) | 8/16 | +0.03 | 0.00 (0.00%) |
|
[Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3)
| +0.39 (+0.32%) | 9/16 | +0.11 | 0.00 (0.00%) |
|
[scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8)
| −0.71 (−0.13%) | 5/16 | −0.51 | −0.01 (0.00%) |
|
[Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a)
| −0.26 (−0.13%) | 6/16 | −0.06 | 0.00 (0.00%) |
|
[Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647)
| +3.33 (+0.23%) | 9/16 | −0.06 | −0.01 (0.00%) |
</details>
<!-- ty-pinned-project-instructions:end -->
---------
Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
|
||
|
|
951401e371 |
[ty] Reuse base lookup inputs across override checks (#31079)
## Summary When checking a declaration such as `sin._eval_is_extended_real`, we look for an override target on each base. The next declaration asks for the same base’s symbol table, generator classification and names written to the receiver. We now keep those inputs for one subclass check and fill them in as needed. On this file, the override loop fetched base symbol tables 152 times, down from 2,654. On a symbol miss we still check synthesized members, including implicit `__hash__`. We can then skip instance lookup if the class’s methods never assign that name to the receiver. This eliminated 2,515 instance lookups in the override loop. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.20% and the median was −0.17%. Weighting each project by its median instruction count on main gives a change of −0.24%. <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/d67aa96e6aa18733304d95ce085add18339d4aef) | [PR instructions](https://github.com/astral-sh/ruff/commit/396321c16a0db912977d7b2c214b8b7cd0f5e37d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,372,352,503 | 2,369,861,650 | -0.10% | -0.11% to -0.10% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,786,140,076 | 5,774,763,367.5 | -0.19% | -0.21% to -0.19% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 115,335,379,908.5 | 115,055,215,473 | -0.24% | -0.24% to -0.24% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,294,853,204.5 | 1,293,825,007.5 | -0.08% | -0.09% to -0.07% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,341,047,732.5 | 1,338,889,703.5 | -0.16% | -0.17% to -0.14% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 20,462,200,131.5 | 20,424,628,317.5 | -0.19% | -0.21% to -0.18% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,285,587,754 | 2,279,603,186 | -0.26% | -0.27% to -0.23% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 3,841,515,815 | 3,840,860,667 | -0.02% | -0.03% to -0.01% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 68,859,654,450 | 68,757,854,316 | -0.15% | -0.15% to -0.14% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,206,814,515.5 | 1,205,319,917.5 | -0.12% | -0.13% to -0.12% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,158,230,963 | 7,146,754,657.5 | -0.16% | -0.18% to -0.14% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,253,148,848 | 2,250,543,159.5 | -0.11% | -0.12% to -0.11% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 14,953,311,747.5 | 14,874,856,223.5 | -0.52% | -0.53% to -0.52% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 1,990,492,910.5 | 1,986,819,877 | -0.17% | -0.20% to -0.17% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 9,897,316,846.5 | 9,869,703,756.5 | -0.28% | -0.28% to -0.28% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 31,566,958,551.5 | 31,474,638,290.5 | -0.29% | -0.30% to -0.29% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 10,976,786,491.5 | 10,937,251,711 | -0.36% | -0.36% to -0.35% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,161,863,369.5 | 6,153,571,774 | -0.13% | -0.14% to -0.13% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,043,766,050 | 3,037,378,316.5 | -0.21% | -0.21% to -0.21% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,422,516,232 | 10,405,840,100 | -0.16% | -0.16% to -0.16% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,191,187,432 | 2,187,104,074.5 | -0.19% | -0.19% to -0.18% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,497,649,711 | 3,489,025,410 | -0.25% | -0.25% to -0.24% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 24,299,762,867.5 | 24,270,139,196 | -0.12% | -0.13% to -0.11% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,099,396,702 | 11,083,340,094.5 | -0.14% | -0.15% to -0.14% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,189,630,955.5 | 6,181,492,250 | -0.13% | -0.13% to -0.13% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 37,337,650,121 | 37,297,139,883.5 | -0.11% | -0.11% to -0.11% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,623,052,966 | 6,608,017,433.5 | -0.23% | -0.23% to -0.22% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 71,866,852,199.5 | 71,566,049,817.5 | -0.42% | -0.42% to -0.42% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.66 (+0.61%) | 13/16 | −0.09 | 0.00 (0.00%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | +0.01 (0.00%) | 8/16 | −0.08 | 0.00 (0.00%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | +0.13 (0.00%) | 8/16 | −0.26 | 0.00 (0.00%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | −0.72 (−1.01%) | 6/16 | +0.19 | 0.00 (0.00%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | +0.27 (+0.34%) | 9/16 | +0.14 | 0.00 (0.00%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +1.59 (+0.31%) | 9/16 | +0.14 | 0.00 (0.00%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −1.18 (−0.89%) | 3/16 | 0.00 | 0.00 (0.00%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | +0.11 (+0.06%) | 8/16 | +0.05 | 0.00 (0.00%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | +0.09 (+0.01%) | 8/16 | +0.19 | 0.00 (0.00%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | −0.04 (−0.05%) | 7/16 | +0.03 | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | −0.05 (−0.03%) | 8/16 | +0.08 | 0.00 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | −0.93 (−0.77%) | 6/16 | +0.10 | 0.00 (0.00%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −0.26 (−0.07%) | 8/16 | −0.15 | 0.00 (0.00%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | +0.38 (+0.38%) | 11/16 | −0.03 | 0.00 (0.00%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +0.21 (+0.08%) | 10/16 | +0.03 | 0.00 (0.00%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | +1.02 (+0.16%) | 10/16 | −0.04 | 0.00 (0.00%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | +0.61 (+0.22%) | 9/16 | +0.22 | 0.00 (0.00%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | −0.15 (−0.07%) | 6/16 | +0.18 | 0.00 (0.00%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.24 (−0.21%) | 6/16 | −0.03 | 0.00 (0.00%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | +0.82 (+0.32%) | 12/16 | +0.09 | 0.00 (0.00%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.31 (−0.30%) | 4/16 | +0.18 | 0.00 (0.00%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | −0.03 (−0.02%) | 7/16 | −0.03 | 0.00 (0.00%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −0.01 (0.00%) | 8/16 | 0.00 | 0.00 (0.00%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | −0.04 (−0.01%) | 8/16 | +0.05 | 0.00 (0.00%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | +0.01 (+0.01%) | 8/16 | +0.06 | 0.00 (0.00%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −0.82 (−0.15%) | 4/16 | −0.02 | 0.00 (0.00%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −0.04 (−0.02%) | 7/16 | +0.05 | 0.00 (0.00%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +0.58 (+0.04%) | 8/16 | −0.04 | 0.00 (0.00%) | </details> <!-- ty-pinned-project-instructions:end --> --------- Co-authored-by: Charlie Marsh <charliemarsh@openai.com> |
||
|
|
46f1d048c3 |
[ty] Defer subtype checks for enum diagnostics until they can apply (#31074)
## Summary Across six paired full Home Assistant checks, wall time changed +2.83% (95% bootstrap interval −4.29% to +11.93%). CPU time changed +2.52% (−4.54% to +12.81%) and peak RSS changed −0.11% (−0.24% to +0.01%). All 13,441 diagnostics and the exit status matched the baseline. These measurements don't establish an end-to-end speedup. Of 15,365 initialized, annotated names we counted in Home Assistant, 11,721 are at module or function scope. We currently ask whether the assigned value is a subtype of `Callable` before checking whether the name could be an enum member. We now check the scope and the enclosing class first. We only do the callable subtype check for a possible enum member. Similarly, when checking whether an enum is generic, we first ask whether the class is generic. A test covers a local annotation in an enum method and a member of a second enum nested inside the method. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.15% and the median was −0.11%. Weighting each project by its median instruction count on main gives a change of −0.16%. We compared cold checks on [main at |
||
|
|
d67aa96e6a |
[ty] Skip overload prefix checks for literal parameters (#31043)
## Summary When the service name is `Any`, we check whether some prefix of the overloads accepts every possible value. A prefix that only accepts literal service names can never cover `object()`. We already use that observation to skip prefix checks for some parameter types. We now recognize literal types here too, including unions where every member excludes `object()`. Checking `boto3auth` with `boto3-stubs` was 7.7% faster on a single worker (112 ms to 104 ms, faster in 17 of 18 paired runs). In `boto3-stubs` 1.44.3, all 435 overloads of `Session.client` take a literal service name. |
||
|
|
a6154c6ed7 |
[ty] Resolve assignments once when interpreting a name as a type (#31018)
## Summary When we see `x: T`, we resolve the definition of `T` to see whether it's a legacy type alias. We can then resolve it again to reject computed values like `T = make_type()`. For an imported class, we follow the import and cache two negative answers. We now return the assignment and its optional alias from the same query. If `T` refers to a class, we can skip the second check. If it refers to an assignment, we know where to look for an invalid expression, even if the alias forwards to another definition. The query stays keyed on the original definition so we detect cycles through imports. The new test covers implicit aliases that forward to each other across two modules. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.39% and the median was −0.35%. Weighting each project by its median instruction count on main gives a change of −0.37%. On Home Assistant, ty cached 843 results for `non_alias_assignment`, down from 73,981. Across 36 paired Linux checks, the median reduction in peak memory was 9.8 MiB. <details> <summary>Instruction counts by project</summary> Both builds use the linked main commit, with this PR applied to the second. Counts are medians of four single-worker Cachegrind runs on Linux (x86-64). Change is the median of four paired percentages. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/c05df9647fbd20e2832120fae9b957a11b668e85) | [PR instructions](https://github.com/astral-sh/ruff/commit/6763000da51c81677472a6596a0a907acb7b3808) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,456,596,876 | 2,447,300,316.5 | -0.38% | -0.40% to -0.37% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,934,860,300.5 | 5,899,449,932.5 | -0.60% | -0.60% to -0.59% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 120,267,955,188 | 119,421,412,176 | -0.70% | -0.71% to -0.70% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,335,841,302 | 1,331,358,455.5 | -0.33% | -0.34% to -0.33% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,387,100,602.5 | 1,382,136,349 | -0.36% | -0.36% to -0.35% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 21,238,507,180 | 21,183,935,287 | -0.26% | -0.27% to -0.25% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,393,950,068 | 2,370,399,700 | -0.98% | -1.01% to -0.96% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,007,292,763 | 3,986,519,579.5 | -0.52% | -0.52% to -0.51% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 71,128,626,466 | 70,960,681,613 | -0.24% | -0.24% to -0.23% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,240,612,798.5 | 1,235,628,138.5 | -0.41% | -0.43% to -0.39% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,450,419,495 | 7,370,949,671.5 | -1.07% | -1.08% to -1.06% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,351,056,692.5 | 2,339,270,437 | -0.50% | -0.51% to -0.49% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 15,519,109,498.5 | 15,469,446,310 | -0.32% | -0.32% to -0.32% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,051,691,761.5 | 2,042,593,638.5 | -0.45% | -0.46% to -0.44% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 10,200,235,496 | 10,184,559,670 | -0.15% | -0.16% to -0.15% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 32,448,008,190 | 32,427,192,069.5 | -0.06% | -0.07% to -0.06% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 11,530,051,415.5 | 11,414,981,425 | -1.00% | -1.00% to -0.99% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,368,350,092 | 6,343,600,478 | -0.39% | -0.39% to -0.39% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,151,445,144 | 3,137,951,610 | -0.43% | -0.44% to -0.42% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,711,346,025 | 10,693,676,521 | -0.17% | -0.17% to -0.16% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,266,445,102.5 | 2,261,954,550.5 | -0.20% | -0.20% to -0.20% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,616,219,135.5 | 3,608,934,779 | -0.20% | -0.20% to -0.20% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 24,960,147,049.5 | 24,924,947,380.5 | -0.14% | -0.15% to -0.12% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,386,138,463 | 11,372,585,378 | -0.12% | -0.12% to -0.12% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,356,319,232 | 6,345,611,801.5 | -0.17% | -0.17% to -0.16% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 38,388,535,283 | 38,344,889,712.5 | -0.11% | -0.12% to -0.11% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,855,922,348 | 6,819,495,020 | -0.53% | -0.53% to -0.53% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 74,218,727,741 | 74,026,939,842.5 | -0.26% | -0.26% to -0.25% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | −0.26 (−0.24%) | 4/16 | −0.04 | −0.11 (−0.17%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | −1.38 (−0.75%) | 5/16 | −0.46 | −0.69 (−0.52%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | −9.39 (−0.29%) | 0/16 | −9.50 | −15.72 (−0.52%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | +0.32 (+0.46%) | 9/16 | +0.09 | −0.06 (−0.17%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | −0.52 (−0.65%) | 4/16 | −0.19 | −0.07 (−0.19%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +3.13 (+0.60%) | 10/16 | −0.31 | −0.79 (−0.18%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −0.44 (−0.33%) | 6/16 | −0.07 | −0.38 (−0.46%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.19 (−0.10%) | 6/16 | −0.09 | −0.38 (−0.27%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | −1.45 (−0.10%) | 7/16 | −0.60 | −2.54 (−0.19%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | −0.38 (−0.45%) | 7/16 | −0.26 | −0.10 (−0.23%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +0.06 (+0.04%) | 8/16 | −0.22 | −2.24 (−1.26%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.17 (+0.14%) | 8/16 | −0.04 | −0.17 (−0.24%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −0.56 (−0.16%) | 8/16 | −0.40 | −0.83 (−0.29%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.37 (−0.36%) | 6/16 | −0.34 | −0.20 (−0.35%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +2.90 (+1.05%) | 14/16 | +2.41 | −0.09 (−0.04%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | +2.13 (+0.34%) | 10/16 | −0.09 | −0.33 (−0.06%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | −1.77 (−0.61%) | 1/16 | −1.76 | −2.33 (−1.04%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | +2.00 (+0.94%) | 13/16 | +2.02 | −0.37 (−0.24%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.12 (−0.10%) | 6/16 | +0.04 | −0.20 (−0.28%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −0.04 (−0.02%) | 8/16 | −0.09 | −0.24 (−0.12%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.33 (−0.31%) | 5/16 | +0.07 | −0.05 (−0.09%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.08 (+0.05%) | 9/16 | −0.11 | −0.09 (−0.10%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −2.66 (−0.48%) | 4/16 | −0.78 | −0.68 (−0.15%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +2.20 (+0.83%) | 15/16 | +1.47 | −0.24 (−0.12%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | −0.52 (−0.40%) | 7/16 | −0.05 | −0.19 (−0.24%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | +0.18 (+0.03%) | 11/16 | −0.39 | −0.93 (−0.18%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −0.62 (−0.30%) | 6/16 | −0.53 | −0.54 (−0.35%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | −3.81 (−0.26%) | 5/16 | −1.39 | −2.96 (−0.22%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
410fcfa599 |
[ty] Reuse union simplification decisions across built-in literals (#30994)
## Summary When checking NumPy's dtype annotations, ty builds unions of class objects and literal strings. The order matters for performance. In `Literal["float", "double"] | type[float]`, ty can check the whole group at once. In `type[float] | Literal["float", "double"]`, ty visits the class for every string, even with the shortcut in [#30728](https://github.com/astral-sh/ruff/pull/30728). We now remember which union members still need to be checked when adding another string, bytes or integer literal. A non-generic nominal instance can absorb all the literals or coexist with all of them. For `type[C]`, we use the metaclass lookup from #30728 to rule out the reverse comparison when the result is a nominal instance. When inserting literals, we still check individual values against types like `Sequence[Literal["a"]]`, which accepts `"aa"` but not `"ab"`, and fall back to the existing comparisons for callable metaclasses returning `Never` and during inference cycles. The builder keeps a list of indices for one literal kind at a time. It allocates the list only when it can skip a comparison, checks newly appended members in order, and discards the list when a member moves or is replaced. The list lives only as long as the builder. As on main, adding a specialized sequence after a literal group can still drop a valid alternative. For example, `Literal["aa", "ab"] | Sequence[Literal["a"]]` loses `"ab"` because `splits_literals` lets `"aa"` stand in for the group. Checking the three NumPy consumers below took 8.8–14.1% fewer instructions than main and 3.2–6.5% fewer than main with #30728 applied. | Wheel | Instructions vs. main | Instructions vs. #30728 | Peak RSS vs. main | | --- | ---: | ---: | ---: | | ml-dtypes 0.6.0 | −14.11% | −6.50% | −4.18 MiB | | plyfile 1.1.5 | −9.54% | −3.19% | −4.48 MiB | | numcodecs 0.17.1 | −8.81% | −4.06% | −4.18 MiB | | packaging 26.2 (control) | −0.25% | −0.25% | −0.11 MiB | <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.12% and the median was −0.06%. Weighting each project by its median instruction count on main gives a change of −0.10%. <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/ad57098ab0ee76c32e4f8edcffbb4fdb0cfc9ea7) | [PR instructions](https://github.com/astral-sh/ruff/commit/e301e72c1c24a384bafe5f315539ed5c2a8d47c6) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,474,216,753.5 | 2,473,652,660.5 | -0.02% | -0.03% to -0.01% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 5,998,481,569 | 5,995,192,776 | -0.05% | -0.06% to -0.05% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 121,396,896,304.5 | 121,340,053,486 | -0.05% | -0.05% to -0.04% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,348,440,692.5 | 1,347,590,894.5 | -0.06% | -0.07% to -0.05% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,406,909,649.5 | 1,406,050,566 | -0.06% | -0.07% to -0.05% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 21,465,850,199.5 | 21,453,597,936 | -0.06% | -0.07% to -0.05% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,445,827,353 | 2,417,539,020.5 | -1.15% | -1.17% to -1.13% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,035,680,902 | 4,035,599,700 | 0.00% | -0.01% to 0.00% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 71,757,943,411 | 71,713,178,286.5 | -0.06% | -0.07% to -0.06% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,262,429,060.5 | 1,262,027,777.5 | -0.02% | -0.07% to -0.02% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,455,729,394.5 | 7,453,319,659.5 | -0.04% | -0.05% to -0.01% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,369,335,922 | 2,369,978,775.5 | +0.03% | +0.01% to +0.03% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 15,688,612,407.5 | 15,682,225,772.5 | -0.04% | -0.05% to -0.03% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,077,056,775 | 2,074,862,163 | -0.11% | -0.11% to -0.11% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 10,359,090,271 | 10,326,461,929.5 | -0.31% | -0.32% to -0.31% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 32,835,921,654 | 32,820,284,441 | -0.05% | -0.05% to -0.05% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 11,643,817,809 | 11,633,051,596 | -0.09% | -0.10% to -0.09% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,444,649,000.5 | 6,439,394,450 | -0.08% | -0.09% to -0.08% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,180,716,264 | 3,179,084,048.5 | -0.05% | -0.05% to -0.05% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,841,652,441.5 | 10,836,171,068 | -0.05% | -0.06% to -0.05% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,297,483,909.5 | 2,295,872,905 | -0.07% | -0.09% to -0.05% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,651,937,993 | 3,648,464,139 | -0.10% | -0.10% to -0.09% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 25,365,470,671.5 | 25,226,401,230 | -0.55% | -0.55% to -0.54% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,555,307,149.5 | 11,548,075,318 | -0.06% | -0.07% to -0.06% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,413,252,840 | 6,416,465,515.5 | +0.05% | +0.04% to +0.05% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 38,924,312,326.5 | 38,845,158,663 | -0.20% | -0.21% to -0.20% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 6,938,483,914.5 | 6,933,710,148 | -0.07% | -0.08% to -0.06% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 75,256,939,278 | 75,203,313,704 | -0.07% | -0.08% to -0.07% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.02 (+0.02%) | 8/16 | +0.07 | −0.04 (−0.06%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | +0.19 (+0.10%) | 9/16 | 0.00 | −0.07 (−0.05%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | +0.25 (+0.01%) | 9/16 | −0.45 | −0.30 (−0.01%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | −0.08 (−0.11%) | 8/16 | +0.10 | −0.07 (−0.20%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | −0.06 (−0.08%) | 7/16 | +0.13 | −0.02 (−0.06%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +2.47 (+0.47%) | 10/16 | −0.43 | −0.38 (−0.09%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | +0.30 (+0.23%) | 8/16 | −1.67 | −0.93 (−1.09%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.25 (−0.13%) | 7/16 | +0.03 | −0.01 (−0.01%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | +1.00 (+0.07%) | 9/16 | −0.03 | −0.18 (−0.01%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | −0.23 (−0.27%) | 5/16 | −0.12 | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | −3.98 (−1.70%) | 4/16 | −0.14 | −0.11 (−0.06%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.10 (+0.08%) | 8/16 | −0.12 | −0.01 (−0.01%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −0.64 (−0.18%) | 6/16 | 0.00 | −0.03 (−0.01%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | +0.32 (+0.31%) | 10/16 | +0.01 | −0.02 (−0.04%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | −0.62 (−0.22%) | 6/16 | −0.32 | −0.36 (−0.17%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | −1.98 (−0.31%) | 5/16 | +0.15 | −0.08 (−0.02%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | −0.19 (−0.07%) | 8/16 | −0.10 | −0.13 (−0.06%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | +0.40 (+0.19%) | 9/16 | −0.18 | −0.07 (−0.05%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | +0.24 (+0.20%) | 9/16 | +0.34 | −0.04 (−0.06%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −0.31 (−0.12%) | 6/16 | +0.23 | −0.10 (−0.05%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.11 (−0.10%) | 8/16 | +0.10 | −0.02 (−0.04%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.36 (+0.26%) | 11/16 | +0.17 | −0.03 (−0.03%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −4.52 (−0.80%) | 0/16 | −4.25 | −3.69 (−0.79%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +0.09 (+0.03%) | 9/16 | −0.26 | −0.17 (−0.09%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | +0.49 (+0.38%) | 10/16 | −0.05 | −0.04 (−0.05%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −3.49 (−0.61%) | 0/16 | −4.14 | −3.25 (−0.63%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −0.05 (−0.02%) | 8/16 | −0.18 | −0.03 (−0.02%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +1.72 (+0.12%) | 9/16 | −0.54 | −0.28 (−0.02%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
ad57098ab0 |
[ty] Skip implicit-return reachability checks for literal None annotations (#30987)
## Summary
On Home Assistant, `ty check --quiet` took 1.18% and 1.45% less wall
time on two Linux machines. In a separate repeat, it took 1.48% and
0.84% less time, respectively. All four 95% intervals favored the
change. Peak memory fell by about 5 MiB, and all 13,441 diagnostics were
identical.
For example, consider a function that sends a notification.
```py
def notify() -> None:
send_notification()
```
Today, ty can bind the call to see if it returns `Never` when deciding
whether control reaches the end of `notify`. Either way, the implicit
return is valid.
We now skip that reachability check for functions with a literal `->
None` annotation. If there are no explicit returns and the function
isn’t a generator, we also avoid looking up the enclosing function and
constructing its return signature. We still check the body, explicit
returns and generator annotations.
About half the functions in Home Assistant have this annotation. In a
separate memory report, ty stored 37% fewer results for checks of
whether a call can return (63,772 → 40,208).
Each machine ran 216 comparisons and a repeat of 144 with default
parallelism and transparent huge pages disabled. The percentages are
median paired reductions against two runs of the same main binary per
comparison. The [ecosystem
check](https://github.com/astral-sh/ruff/actions/runs/45921699079)
showed no stable diagnostic changes. The intermittent messages in
steam.py also appeared on main.
<!-- ty-pinned-project-instructions:start -->
Measured 4 of 28 projects.
We compared cold checks on [main at
|
||
|
|
7b3746e595 |
[ty] Build bound method overloads directly in the callable binding (#30972)
## Summary A single-threaded check of discord.py used 0.17% fewer instructions on Linux. Black, Django, and FastAPI used 0.05% to 0.12% fewer instructions. We didn't see a clear change in elapsed time. Specializing a method for its receiver can turn one overload into several. We account for that by collecting a list of signatures for each overload and flattening the lists into the callable binding. In the common case, the intermediate list contains just one signature. We now reserve space for the declared overloads and append signatures directly to the binding as we specialize them. If a signature has a source index, we keep it so diagnostics still point to the original declaration. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.05% and the median was −0.03%. Weighting each project by its median instruction count on main gives a change of −0.05%. <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/8f0189e0e975334474efb938eafc48f22855aadb) | [PR instructions](https://github.com/astral-sh/ruff/commit/3ab336395500d439f03c59859ddad38fd1d59eb2) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,519,118,538.5 | 2,518,266,207.5 | -0.03% | -0.05% to -0.03% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 6,094,023,132 | 6,083,580,011.5 | -0.17% | -0.17% to -0.17% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 122,815,007,477 | 122,778,166,954.5 | -0.03% | -0.03% to -0.03% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,375,648,340.5 | 1,374,896,904.5 | -0.06% | -0.06% to -0.05% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,442,647,695.5 | 1,441,963,823 | -0.05% | -0.06% to -0.03% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 21,641,226,887 | 21,619,770,014.5 | -0.10% | -0.11% to -0.10% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,485,332,838 | 2,482,956,272 | -0.09% | -0.10% to -0.09% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,103,517,096 | 4,101,845,863.5 | -0.04% | -0.04% to -0.04% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 72,340,041,831.5 | 72,319,129,347 | -0.03% | -0.03% to -0.03% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,294,737,622.5 | 1,294,534,543.5 | -0.02% | -0.03% to -0.01% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 7,575,400,317.5 | 7,575,466,043 | +0.01% | -0.01% to +0.02% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,414,749,016 | 2,411,287,936 | -0.14% | -0.14% to -0.14% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 15,855,140,588 | 15,842,572,942.5 | -0.08% | -0.08% to -0.08% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,123,209,404 | 2,123,718,828.5 | +0.02% | +0.02% to +0.03% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 10,419,829,371 | 10,417,941,540.5 | -0.02% | -0.02% to -0.02% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 33,065,014,877 | 33,058,817,145 | -0.02% | -0.02% to -0.02% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 11,756,838,743 | 11,755,836,338 | -0.01% | -0.01% to 0.00% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,570,127,927.5 | 6,567,381,972.5 | -0.04% | -0.05% to -0.04% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,236,384,044.5 | 3,235,945,041 | -0.01% | -0.01% to -0.01% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 10,941,438,561.5 | 10,935,218,232.5 | -0.06% | -0.06% to -0.05% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,336,526,199 | 2,335,941,201.5 | -0.03% | -0.03% to -0.02% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 3,705,928,064 | 3,705,789,801 | 0.00% | -0.02% to +0.01% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 25,572,934,186.5 | 25,566,255,021.5 | -0.03% | -0.04% to -0.02% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,666,069,289.5 | 11,662,417,786 | -0.03% | -0.03% to -0.03% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,464,537,443 | 6,451,829,469.5 | -0.20% | -0.21% to -0.19% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 39,258,601,979 | 39,197,794,305.5 | -0.16% | -0.16% to -0.15% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 7,075,193,190 | 7,073,576,224.5 | -0.02% | -0.02% to -0.02% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 75,643,384,613.5 | 75,626,699,375 | -0.02% | -0.03% to -0.02% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | +0.26 (+0.24%) | 10/16 | +0.09 | 0.00 (0.00%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | −0.56 (−0.30%) | 7/16 | −0.01 | 0.00 (0.00%) | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | +0.19 (+0.01%) | 8/16 | +0.24 | 0.00 (0.00%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | +1.01 (+1.39%) | 13/16 | +0.58 | 0.00 (0.00%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | −0.04 (−0.05%) | 8/16 | +0.19 | 0.00 (0.00%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | +1.90 (+0.36%) | 11/16 | −0.24 | 0.00 (0.00%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −0.10 (−0.07%) | 8/16 | +0.02 | 0.00 (0.00%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | +0.72 (+0.37%) | 11/16 | +0.29 | 0.00 (0.00%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | −0.66 (−0.05%) | 7/16 | +0.67 | 0.00 (0.00%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | +0.18 (+0.21%) | 12/16 | −0.04 | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +2.59 (+1.12%) | 9/16 | +1.48 | 0.00 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | −0.14 (−0.11%) | 7/16 | −0.24 | 0.00 (0.00%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | +0.49 (+0.14%) | 10/16 | +0.04 | 0.00 (0.00%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.48 (−0.46%) | 7/16 | −0.18 | 0.00 (0.00%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 0.00 (0.00%) | 8/16 | −0.16 | 0.00 (0.00%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | −2.52 (−0.39%) | 4/16 | +0.32 | 0.00 (0.00%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | −0.14 (−0.05%) | 7/16 | −0.01 | 0.00 (0.00%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | +0.10 (+0.05%) | 8/16 | 0.00 | 0.00 (0.00%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −0.19 (−0.17%) | 5/16 | −0.11 | 0.00 (0.00%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −0.49 (−0.19%) | 6/16 | +0.46 | 0.00 (0.00%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.13 (−0.12%) | 8/16 | −0.10 | 0.00 (0.00%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | +0.15 (+0.11%) | 8/16 | +0.08 | 0.00 (0.00%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −0.21 (−0.04%) | 7/16 | −0.21 | 0.00 (0.00%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +0.48 (+0.18%) | 11/16 | +0.13 | 0.00 (0.00%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | +0.17 (+0.13%) | 9/16 | −0.19 | 0.00 (0.00%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −0.25 (−0.04%) | 6/16 | −0.09 | 0.00 (0.00%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −0.49 (−0.23%) | 6/16 | +0.13 | 0.00 (0.00%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | +0.13 (+0.01%) | 9/16 | +0.49 | 0.00 (0.00%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
eae51d5c35 |
[ty] Move class and type alias queries off Definition (#30955)
## Summary On cold checks with default parallelism, the median reduction in peak memory (RSS) across projects was about 1%. We saved 32 MiB on Transformers, 24 MiB on PyTorch, and 4.8 MiB on Django. The memo table for each definition shrinks from 200 to 160 bytes. A check of Django allocates about 73,000 of these tables. When Salsa caches the first query result for a `Definition`, it allocates a slot for every query keyed by `Definition`. Even a local variable gets five slots for queries that only apply to a dynamically created class or a PEP 695 type alias. We now key the queries for `type()`, `NamedTuple()` and `TypedDict()` on the classes they create. We key Pydantic’s strictness check on the unspecialized alias, so `StrictField[int]` and `StrictField[str]` still share the result. <!-- ty-pinned-project-instructions:start --> <details> <summary>Instruction counts by project</summary> Both builds use the linked main commit, with this PR applied to the second. Counts are medians of four single-worker Cachegrind runs on Linux (x86-64). Change is the median of four paired percentages. We marked a result inconclusive when the pairs disagreed in direction or the change was within the variation between runs of either build. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/9f70bdad1a3869e0190e5ef7014380861e34fec4) | [PR instructions](https://github.com/astral-sh/ruff/commit/bbd38e452bf96bc2c84263367d3889b9ac2de74d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,575,844,391 | 2,575,466,716.5 | -0.02% | -0.03% to -0.01% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | 6,278,777,961.5 | 6,277,491,552.5 | -0.02% | -0.03% to -0.01% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,402,514,191 | 1,402,124,666 | -0.03% | -0.05% to -0.01% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,474,312,528.5 | 1,473,667,190 | -0.05% | -0.06% to -0.02% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | 22,132,375,634 | 22,109,351,376.5 | -0.10% | -0.11% to -0.09% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | 2,517,651,816.5 | 2,514,723,837.5 | -0.12% | -0.14% to -0.10% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,153,334,191 | 4,152,837,185 | -0.01% | -0.02% to -0.01% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 74,750,182,236 | 74,750,938,935.5 | 0.00% | -0.01% to +0.01% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,308,290,903.5 | 1,308,395,083 | +0.01% | -0.02% to +0.03% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,747,407,091 | 7,755,315,052 | +0.10% | +0.01% to +0.13% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,463,449,690 | 2,463,449,515.5 | 0.00% | -0.01% to +0.02% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | 16,255,369,079.5 | 16,248,322,685.5 | -0.04% | -0.05% to -0.04% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,171,296,619 | 2,171,098,849.5 | -0.01% | -0.01% to 0.00% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 10,771,745,213.5 | 10,771,924,951.5 | 0.00% | 0.00% to +0.01% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | 34,104,369,146.5 | 34,102,640,826.5 | -0.01% | -0.01% to 0.00% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 12,015,531,396 | 11,984,348,757 | -0.26% | -0.26% to -0.25% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 6,751,434,494.5 | 6,753,042,401 | +0.02% | +0.01% to +0.04% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,317,857,858.5 | 3,316,723,052.5 | -0.03% | -0.04% to -0.03% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 11,229,128,755 | 11,230,249,509 | +0.01% | +0.01% to +0.01% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,408,702,393 | 2,409,041,309.5 | +0.01% | 0.00% to +0.02% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,811,450,499.5 | 3,811,092,268 | -0.01% | -0.01% to -0.01% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | 26,065,609,183.5 | 26,060,489,394 | -0.02% | -0.02% to -0.02% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,984,251,057 | 11,987,993,934.5 | +0.03% | +0.02% to +0.04% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,558,247,978.5 | 6,559,203,072 | +0.02% | +0.01% to +0.02% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 40,041,083,099 | 40,050,987,040.5 | +0.03% | +0.02% to +0.03% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | 7,292,109,135.5 | 7,293,506,722 | +0.02% | +0.02% to +0.02% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 78,355,717,428.5 | 78,347,658,604 | -0.01% | -0.02% to 0.00% | </details> <details> <summary>Memory by project</summary> Peak RSS is the median paired change in MiB. We ran 16 pairs with default parallelism and four with one worker. The last column estimates retained query storage from two separate single-worker pairs. It excludes some allocations. | Project | Peak RSS (MiB) | Pairs with higher RSS | Peak RSS, one worker (MiB) | Estimated query storage (MiB) | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | −0.94 (−0.84%) | 3/16 | −0.63 | 0.00 (0.00%) | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) | −1.36 (−0.71%) | 3/16 | −1.75 | 0.00 (0.00%) | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | −0.45 (−0.63%) | 6/16 | −0.28 | 0.00 (0.00%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | −0.24 (−0.29%) | 5/16 | −0.32 | 0.00 (0.00%) | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) | −6.19 (−1.15%) | 3/16 | −4.77 | 0.00 (0.00%) | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) | −0.65 (−0.48%) | 5/16 | −0.45 | 0.00 (0.00%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −1.02 (−0.52%) | 2/16 | −0.84 | 0.00 (0.00%) | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | −24.25 (−1.66%) | 0/16 | −25.38 | 0.00 (0.00%) | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | +0.13 (+0.15%) | 9/16 | −0.14 | 0.00 (0.00%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +1.61 (+0.69%) | 9/16 | −1.98 | 0.00 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | −0.56 (−0.46%) | 6/16 | −0.44 | 0.00 (0.00%) | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) | −5.96 (−1.64%) | 3/16 | −4.45 | 0.00 (0.00%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.39 (−0.37%) | 6/16 | −0.41 | 0.00 (0.00%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | −4.83 (−1.71%) | 0/16 | −4.45 | 0.00 (0.00%) | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) | −13.74 (−2.12%) | 0/16 | −11.71 | 0.00 (0.00%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | −4.90 (−1.64%) | 1/16 | −4.98 | 0.00 (0.00%) | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | −1.74 (−0.80%) | 3/16 | −2.20 | 0.00 (0.00%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | −1.55 (−1.33%) | 0/16 | −0.88 | 0.00 (0.00%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | −3.57 (−1.32%) | 1/16 | −3.18 | 0.00 (0.00%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | −0.83 (−0.76%) | 3/16 | −1.19 | 0.00 (0.00%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | −1.12 (−0.78%) | 2/16 | −1.47 | 0.00 (0.00%) | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) | −6.22 (−1.09%) | 0/16 | −5.37 | 0.00 (0.00%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | −4.04 (−1.50%) | 0/16 | −4.06 | 0.00 (0.00%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | −1.55 (−1.20%) | 1/16 | −0.55 | 0.00 (0.00%) | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | −7.54 (−1.29%) | 0/16 | −8.31 | 0.00 (0.00%) | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) | −3.67 (−1.71%) | 0/16 | −3.25 | 0.00 (0.00%) | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | −32.36 (−2.15%) | 0/16 | −32.01 | 0.00 (0.00%) | </details> <!-- ty-pinned-project-instructions:end --> |
||
|
|
2742584d87 |
[ty] attrs: Support field converter decorators (#30959)
## Summary
attrs lets you register a method as a converter for a field using
`@<field>.converter`. In this example, ty now accepts `str | float` for
`age` in the generated `__init__` and on assignment. Reading `age` still
gives `int`.
```py
from attrs import define, field
@define
class Person:
age: int = field()
@age.converter
def _convert_age(self, attr: object, value: str | float) -> int:
return int(value)
person = Person(age=36.5)
person.age = "37"
reveal_type(person.age) # int
```
If a field has multiple converters, the first one determines the input
type.
See https://github.com/astral-sh/ty/issues/2404#issuecomment-7190831706
|