Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Apr 13, 2024
1 parent e9870fe commit 1536efc
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 0 deletions.
75 changes: 75 additions & 0 deletions crates/ruff_python_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,4 +1521,79 @@ a,b
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
<<<<<<< Updated upstream
||||||| Stash base

#[test]
fn test_stringized_annotation() {
let parse_ast = parse_suite(
r#"
from typing_extensions import TypeAlias
Alias1 = (
int
| str
| bool
) # parentheses required
Alias2: TypeAlias = """
int
| str
| bool
"""
"#
.trim(),
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
=======

#[test]
fn test_alias_stringized_annotation() {
let parse_ast = parse_suite(
r#"
from typing_extensions import TypeAlias
Alias1 = (
int
| str
| bool
) # parentheses required
Alias2: TypeAlias = """
int
| str
| bool
"""
"#
.trim(),
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}

#[test]
fn test_stringized_annotation() {
let parse_ast = parse_suite(
r#"
x: """
int |
str
"""
y: """(
int |
str
)"""
"#
.trim(),
)
.unwrap();
insta::assert_debug_snapshot!(parse_ast);
}
>>>>>>> Stashed changes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
source: crates/ruff_python_parser/src/parser.rs
expression: parse_ast
---
[
ImportFrom(
StmtImportFrom {
range: 0..39,
module: Some(
Identifier {
id: "typing_extensions",
range: 5..22,
},
),
names: [
Alias {
range: 30..39,
name: Identifier {
id: "TypeAlias",
range: 30..39,
},
asname: None,
},
],
level: Some(
0,
),
},
),
Assign(
StmtAssign {
range: 42..83,
targets: [
Name(
ExprName {
range: 42..48,
id: "Alias1",
ctx: Store,
},
),
],
value: BinOp(
ExprBinOp {
range: 57..81,
left: BinOp(
ExprBinOp {
range: 57..70,
left: Name(
ExprName {
range: 57..60,
id: "int",
ctx: Load,
},
),
op: BitOr,
right: Name(
ExprName {
range: 67..70,
id: "str",
ctx: Load,
},
),
},
),
op: BitOr,
right: Name(
ExprName {
range: 77..81,
id: "bool",
ctx: Load,
},
),
},
),
},
),
AnnAssign(
StmtAnnAssign {
range: 109..165,
target: Name(
ExprName {
range: 109..115,
id: "Alias2",
ctx: Store,
},
),
annotation: Name(
ExprName {
range: 117..126,
id: "TypeAlias",
ctx: Load,
},
),
value: Some(
StringLiteral(
ExprStringLiteral {
range: 129..165,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 129..165,
value: "\n int\n | str\n | bool\n",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: true,
},
},
),
},
},
),
),
simple: true,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
source: crates/ruff_python_parser/src/parser.rs
expression: parse_ast
---
[
AnnAssign(
StmtAnnAssign {
range: 0..27,
target: Name(
ExprName {
range: 0..1,
id: "x",
ctx: Store,
},
),
annotation: StringLiteral(
ExprStringLiteral {
range: 3..27,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 3..27,
value: "\n\n int |\n str\n",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: true,
},
},
),
},
},
),
value: None,
simple: true,
},
),
AnnAssign(
StmtAnnAssign {
range: 29..59,
target: Name(
ExprName {
range: 29..30,
id: "y",
ctx: Store,
},
),
annotation: StringLiteral(
ExprStringLiteral {
range: 32..59,
value: StringLiteralValue {
inner: Single(
StringLiteral {
range: 32..59,
value: "(\n int |\n str\n)",
flags: StringLiteralFlags {
quote_style: Double,
prefix: Empty,
triple_quoted: true,
},
},
),
},
},
),
value: None,
simple: true,
},
),
]

0 comments on commit 1536efc

Please sign in to comment.