ruff/crates/ruff_python_semantic/src
Charlie Marsh 1a65e544c5
Allow flake8-type-checking rules to automatically quote runtime-evaluated references (#6001)
## Summary

This allows us to fix usages like:

```python
from pandas import DataFrame

def baz() -> DataFrame:
    ...
```

By quoting the `DataFrame` in `-> DataFrame`. Without quotes, moving
`from pandas import DataFrame` into an `if TYPE_CHECKING:` block will
fail at runtime, since Python tries to evaluate the annotation to add it
to the function's `__annotations__`.

Unfortunately, this does require us to split our "annotation kind" flags
into three categories, rather than two:

- `typing-only`: The annotation is only evaluated at type-checking-time.
- `runtime-evaluated`: Python will evaluate the annotation at runtime
(like above) -- but we're willing to quote it.
- `runtime-required`: Python will evaluate the annotation at runtime
(like above), and some library (like Pydantic) needs it to be available
at runtime, so we _can't_ quote it.

This functionality is gated behind a setting
(`flake8-type-checking.quote-annotations`).

Closes https://github.com/astral-sh/ruff/issues/5559.
2023-12-13 03:12:38 +00:00
..
analyze Add named expression handling to find_assigned_value (#9109) 2023-12-12 20:07:33 -05:00
binding.rs Add a BindingKind for WithItem variables (#8594) 2023-11-09 22:44:49 -05:00
branches.rs Add branch detection to the semantic model (#6694) 2023-08-19 21:28:17 +00:00
context.rs Remove separate ReferenceContext enum (#4631) 2023-05-24 15:12:38 +00:00
definition.rs Add fix for future-required-type-annotation (#8711) 2023-11-16 03:08:02 +00:00
globals.rs Move Ranged into ruff_text_size (#6919) 2023-08-27 14:12:51 -04:00
lib.rs Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04:00
model.rs Allow flake8-type-checking rules to automatically quote runtime-evaluated references (#6001) 2023-12-13 03:12:38 +00:00
nodes.rs Move {AnyNodeRef, AstNode} to ruff_python_ast crate root (#8030) 2023-10-18 00:01:18 +00:00
reference.rs Allow flake8-type-checking rules to automatically quote runtime-evaluated references (#6001) 2023-12-13 03:12:38 +00:00
scope.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00
star_import.rs Move StarImport to its own module (#5186) 2023-06-20 13:12:46 -04:00