mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-10 06:35:07 +00:00
![]() This PR updates the semantic model for Python 3.14 by essentially equating "run using Python 3.14" with "uses `from __future__ import annotations`". While this is not technically correct under the hood, it appears to be correct for the purposes of our semantic model. That is: from the point of view of deciding when to parse, bind, etc. annotations, these two contexts behave the same. More generally these contexts behave the same unless you are performing some kind of introspection like the following: Without future import: ```pycon >>> from annotationlib import get_annotations,Format >>> def foo()->Bar:... ... >>> get_annotations(foo,format=Format.FORWARDREF) {'return': ForwardRef('Bar')} >>> get_annotations(foo,format=Format.STRING) {'return': 'Bar'} >>> get_annotations(foo,format=Format.VALUE) Traceback (most recent call last): [...] NameError: name 'Bar' is not defined >>> get_annotations(foo) Traceback (most recent call last): [...] NameError: name 'Bar' is not defined ``` With future import: ``` >>> from __future__ import annotations >>> from annotationlib import get_annotations,Format >>> def foo()->Bar:... ... >>> get_annotations(foo,format=Format.FORWARDREF) {'return': 'Bar'} >>> get_annotations(foo,format=Format.STRING) {'return': 'Bar'} >>> get_annotations(foo,format=Format.VALUE) {'return': 'Bar'} >>> get_annotations(foo) {'return': 'Bar'} ``` (Note: the result of the last call to `get_annotations` in these examples relies on the fact that, as of this writing, the default value for `format` is `Format.VALUE`). If one day we support lint rules targeting code that introspects using the new `annotationlib`, then it is possible we will need to revisit our approximation. Closes #15100 |
||
---|---|---|
.. | ||
src | ||
ast.toml | ||
Cargo.toml | ||
generate.py |