Render an annotation to (type, nullable). `Optional[T]` / `Mapped[T]` unwrap.
(expression: &Expression)
| 664 | |
| 665 | /// Render an annotation to (type, nullable). `Optional[T]` / `Mapped[T]` unwrap. |
| 666 | fn annotation_type(expression: &Expression) -> (String, bool) { |
| 667 | match expression { |
| 668 | Expression::Name(NameExpression { id, .. }) => (id.to_string(), false), |
| 669 | Expression::Subscript(value) => { |
| 670 | let Expression::Name(NameExpression { id, .. }) = &*value.value else { |
| 671 | return (String::new(), false); |
| 672 | }; |
| 673 | |
| 674 | match id.as_str() { |
| 675 | "Mapped" => annotation_type(&value.slice), |
| 676 | "Optional" => { |
| 677 | let (inner, _) = annotation_type(&value.slice); |
| 678 | (inner, true) |
| 679 | } |
| 680 | value => (value.to_string(), false), |
| 681 | } |
| 682 | } |
| 683 | _ => (String::from("unknown"), false), |
| 684 | } |
| 685 | } |
| 686 |