ruff
d467a47a - [ty] Skip checking for unassigned `Final` names in scopes without `Final` declarations (#30946)

Commit
1 day ago
[ty] Skip checking for unassigned `Final` names in scopes without `Final` declarations (#30946) ## Summary To report a `Final` name that never gets a value, we resolve the declarations in scope at the end of each module or function. We do this even if none of the declarations are `Final`. We already visit the inferred declarations when checking the scope. We now use their qualifiers to decide whether we need that second pass. We check the qualifier before looking for an inner type so that a bare `x: Final` still gets a diagnostic. <!-- ty-pinned-project-instructions:start --> Measured 14 of 28 projects. We compared cold checks on [main at 9f70bdad](https://github.com/astral-sh/ruff/commit/9f70bdad1a3869e0190e5ef7014380861e34fec4) and the same commit with [this PR at b256d1b5](https://github.com/astral-sh/ruff/commit/b256d1b519c1023af4686793c91c0cd6cad81d2d) applied. On Django, both builds alternated between `Divergent` and `Unknown` in the same two diagnostics with default parallelism. All single-worker checks matched byte for byte. <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/9f70bdad1a3869e0190e5ef7014380861e34fec4) | [PR instructions](https://github.com/astral-sh/ruff/commit/b256d1b519c1023af4686793c91c0cd6cad81d2d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 2,575,760,869 | 2,572,384,279 | -0.13% | -0.15% to -0.11% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | 1,477,668,940 | 1,474,525,721 | -0.22% | -0.24% to -0.19% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,153,210,688 | 4,150,605,861.5 | -0.06% | -0.07% to -0.06% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | 7,827,689,283 | 7,818,431,895.5 | -0.12% | -0.12% to -0.10% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | 2,463,188,785 | 2,459,323,628 | -0.16% | -0.18% to -0.15% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | 2,171,560,911 | 2,166,353,900.5 | -0.24% | -0.24% to -0.23% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | 10,794,026,814.5 | 10,766,124,900 | -0.26% | -0.26% to -0.25% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 12,044,581,573.5 | 12,008,244,796.5 | -0.30% | -0.31% to -0.30% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | 3,317,348,553.5 | 3,310,816,283.5 | -0.20% | -0.20% to -0.19% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 11,257,733,441 | 11,236,568,743 | -0.19% | -0.19% to -0.19% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | 2,408,965,191.5 | 2,402,895,866 | -0.25% | -0.26% to -0.25% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | 3,811,239,144 | 3,802,800,991 | -0.22% | -0.23% to -0.22% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | 11,994,493,773 | 11,964,295,069.5 | -0.25% | -0.25% to -0.25% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 6,548,936,703.5 | 6,542,441,921.5 | -0.10% | -0.10% to -0.09% | </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.12 (−0.10%) | 8/16 | +0.03 | 0.00 (−0.01%) | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) | +0.01 (+0.01%) | 9/16 | −0.06 | −0.01 (−0.02%) | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | −0.05 (−0.03%) | 8/16 | −0.12 | −0.01 (−0.01%) | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) | +0.77 (+0.32%) | 9/16 | −0.49 | 0.00 (0.00%) | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) | +0.51 (+0.42%) | 10/16 | +0.02 | −0.02 (−0.02%) | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) | −0.52 (−0.50%) | 7/16 | −0.14 | −0.02 (−0.03%) | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) | +0.49 (+0.18%) | 9/16 | +0.14 | 0.00 (0.00%) | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | +0.14 (+0.05%) | 10/16 | −0.07 | −0.10 (−0.05%) | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) | +0.23 (+0.20%) | 10/16 | +0.03 | −0.03 (−0.04%) | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | +0.08 (+0.03%) | 9/16 | −0.16 | −0.02 (−0.01%) | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) | +0.05 (+0.04%) | 8/16 | +0.13 | 0.00 (0.00%) | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) | −0.35 (−0.24%) | 4/16 | −0.23 | 0.00 (0.00%) | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) | +0.43 (+0.16%) | 9/16 | +0.18 | −0.01 (0.00%) | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | −0.45 (−0.35%) | 6/16 | +0.01 | −0.05 (−0.07%) | </details> <!-- ty-pinned-project-instructions:end -->
Author
Parents
Loading