pub fn parse_string_annotation(
source: &str,
string: &StringLiteral,
) -> Result<Parsed<ModExpression>, ParseError>Expand description
Parses a Python expression from a string annotation.
ยงExample
Parsing a string annotation:
use ruff_python_parser::parse_string_annotation;
use ruff_python_ast::{StringLiteral, StringLiteralFlags, AtomicNodeIndex};
use ruff_text_size::{TextRange, TextSize};
let string = StringLiteral {
value: "'''\n int | str'''".to_string().into_boxed_str(),
flags: StringLiteralFlags::empty(),
range: TextRange::new(TextSize::new(0), TextSize::new(16)),
node_index: AtomicNodeIndex::NONE
};
let parsed = parse_string_annotation("'''\n int | str'''", &string);
assert!(!parsed.is_ok());