mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-23 01:50:49 +08:00
## Summary A module that uses `from OpenGL.GL import *` may only use a few of the names it imports. When checking the module, ty infers a binding for every reachable name and then discards those bindings. We now infer them when a name is looked up. We still check assignments to declared names, including implicit module globals, and imports from modules that may define `__getattr__`. Both can produce diagnostics at the import site. Checking the 3,000 files selected by default in [PyOpenGL 3.1.10](https://github.com/mcfletch/pyopengl/tree/bca277036974e5ed9567b90c8176f8c09cd035ec) used 38.35–38.50% fewer instructions. Median peak RSS fell from 718 to 595 MiB. All 2,667 diagnostics matched, including 57 unresolved imports. Before the rebase, checking [pyEarth](https://github.com/afourmy/pyEarth/tree/fe6a87338a6e9592483e08af9ca937d9483d1f0a), a small application that imports PyOpenGL, used 49.17–49.21% fewer instructions with all imports resolved. <!-- ty-pinned-project-instructions:start --> Across 28 projects, the mean change in instructions was −0.01% and the median was 0.00%. <details> <summary>Instruction counts by project</summary> | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/7be385f21d0848e58668b75cd90d0927637c84b6) | [PR instructions](https://github.com/astral-sh/ruff/commit/75ce7e01e66b78bb4f127b57fe2443aa1787d21e) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) (inconclusive) | 3,097,796,122 | 3,096,661,159 | -0.04% | -0.07% to 0.00% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 7,944,816,845.5 | 7,943,562,203.5 | -0.02% | -0.04% to +0.01% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) | 152,987,576,441.5 | 153,029,414,668 | +0.03% | +0.02% to +0.04% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) (inconclusive) | 1,800,612,056.5 | 1,802,154,052.5 | +0.09% | -0.02% to +0.20% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,888,089,270 | 1,887,149,873.5 | -0.05% | -0.10% to 0.00% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 27,346,534,996.5 | 27,329,856,993 | -0.06% | -0.11% to -0.01% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,866,884,571.5 | 2,860,549,231 | -0.22% | -0.27% to -0.17% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) (inconclusive) | 4,849,517,508 | 4,849,672,258.5 | 0.00% | -0.06% to +0.06% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) (inconclusive) | 92,757,122,483 | 92,753,759,377 | 0.00% | -0.02% to +0.01% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) | 1,644,690,168 | 1,640,273,812 | -0.27% | -0.36% to -0.18% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 8,091,322,176.5 | 8,073,878,815.5 | -0.22% | -0.24% to -0.19% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,932,612,584 | 2,936,075,704.5 | +0.12% | +0.11% to +0.13% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 20,599,262,212.5 | 20,595,154,910.5 | -0.02% | -0.10% to +0.06% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,654,741,484.5 | 2,654,534,596.5 | -0.01% | -0.35% to +0.34% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 13,336,107,857 | 13,366,226,325.5 | +0.23% | +0.18% to +0.27% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 44,297,301,099.5 | 44,330,368,859 | +0.07% | 0.00% to +0.15% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) (inconclusive) | 15,299,106,116 | 15,320,875,493 | +0.14% | +0.05% to +0.23% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) (inconclusive) | 8,547,482,632.5 | 8,546,277,159 | -0.01% | -0.02% to -0.01% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,045,619,161 | 4,046,328,155.5 | +0.02% | -0.05% to +0.09% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) (inconclusive) | 13,966,876,210.5 | 13,965,283,668.5 | -0.01% | -0.08% to +0.05% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 2,919,611,682.5 | 2,918,776,857 | -0.03% | -0.10% to +0.04% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,625,150,819 | 4,629,545,744.5 | +0.10% | +0.06% to +0.13% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 32,371,702,667 | 32,384,114,751.5 | +0.04% | -0.07% to +0.14% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 15,086,273,430.5 | 15,090,320,878 | +0.03% | +0.01% to +0.05% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 12,913,874,438 | 12,923,477,137.5 | +0.07% | +0.07% to +0.08% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) | 57,141,632,292.5 | 57,198,197,831 | +0.10% | +0.06% to +0.14% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,665,409,763.5 | 8,670,127,790 | +0.05% | +0.03% to +0.08% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) | 95,912,555,401 | 95,547,172,172.5 | -0.38% | -0.41% to -0.35% | </details> <!-- ty-pinned-project-instructions:end -->