mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Enable annotation quoting for multi-line expressions (#9142)
Given: ```python x: DataFrame[ int ] = 1 ``` We currently wrap the annotation in single quotes, which leads to a syntax error: ```python x: "DataFrame[ int ]" = 1 ``` There are a few options for what to suggest for users here... Use triple quotes: ```python x: """DataFrame[ int ]""" = 1 ``` Or, use an implicit string concatenation (which may require parentheses): ```python x: ("DataFrame[" "int" "]") = 1 ``` The solution I settled on here is to use the `Generator`, which effectively means we write it out on a single line, like: ```python x: "DataFrame[int]" = 1 ``` It's kind of the "least opinionated" solution, but it does mean we'll expand to a very long line in some cases. Closes https://github.com/astral-sh/ruff/issues/9136.
This commit is contained in:
parent
6c224cec52
commit
d1a7bc38ff
6 changed files with 113 additions and 14 deletions
|
@ -7,7 +7,7 @@ use ruff_text_size::{Ranged, TextRange, TextSize};
|
|||
|
||||
/// A text edit to be applied to a source file. Inserts, deletes, or replaces
|
||||
/// content at a given location.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct Edit {
|
||||
/// The start location of the edit.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue