ruff
d9066db9 - [ty] Filter TypedDict.get overloads by key and arity (#30868)

Commit
20 hours ago
[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>
Author
Parents
Loading