1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::{Constant, Expr};

impl<R> Expr<R> {
    /// Returns a short name for the node suitable for use in error messages.
    pub fn python_name(&self) -> &'static str {
        match self {
            Expr::BoolOp { .. } | Expr::BinOp { .. } | Expr::UnaryOp { .. } => "operator",
            Expr::Subscript { .. } => "subscript",
            Expr::Await { .. } => "await expression",
            Expr::Yield { .. } | Expr::YieldFrom { .. } => "yield expression",
            Expr::Compare { .. } => "comparison",
            Expr::Attribute { .. } => "attribute",
            Expr::Call { .. } => "function call",
            Expr::Constant(crate::ExprConstant { value, .. }) => match value {
                Constant::Str(_)
                | Constant::Int(_)
                | Constant::Float(_)
                | Constant::Complex { .. }
                | Constant::Bytes(_) => "literal",
                Constant::Tuple(_) => "tuple",
                Constant::Bool(b) => {
                    if *b {
                        "True"
                    } else {
                        "False"
                    }
                }
                Constant::None => "None",
                Constant::Ellipsis => "ellipsis",
            },
            Expr::List { .. } => "list",
            Expr::Tuple { .. } => "tuple",
            Expr::Dict { .. } => "dict display",
            Expr::Set { .. } => "set display",
            Expr::ListComp { .. } => "list comprehension",
            Expr::DictComp { .. } => "dict comprehension",
            Expr::SetComp { .. } => "set comprehension",
            Expr::GeneratorExp { .. } => "generator expression",
            Expr::Starred { .. } => "starred",
            Expr::Slice { .. } => "slice",
            Expr::JoinedStr(crate::ExprJoinedStr { values, .. }) => {
                if values.iter().any(|e| e.is_joined_str_expr()) {
                    "f-string expression"
                } else {
                    "literal"
                }
            }
            Expr::FormattedValue { .. } => "f-string expression",
            Expr::Name { .. } => "name",
            Expr::Lambda { .. } => "lambda",
            Expr::IfExp { .. } => "conditional expression",
            Expr::NamedExpr { .. } => "named expression",
        }
    }
}

// TODO: make this a #[test] to avoid eq comparison
// #[cfg(target_arch = "x86_64")]
// static_assertions::assert_eq_size!(crate::Expr, [u8; 72]);
// #[cfg(target_arch = "x86_64")]
// static_assertions::assert_eq_size!(crate::Stmt, [u8; 160]);
// #[cfg(target_arch = "x86_64")]
// static_assertions::assert_eq_size!(crate::Pattern, [u8; 96]);
// #[cfg(target_arch = "x86_64")]
// static_assertions::assert_eq_size!(crate::ExceptHandler, [u8; 64]);