monty_types/builtins.rs
1//! [`BuiltinsFunctions`] — the name-level identity of every interpreter-native
2//! Python builtin, carried by [`MontyObject::builtin_function`](crate::MontyObject::builtin_function).
3
4use strum::{Display, EnumString, FromRepr, IntoStaticStr, VariantNames};
5/// Enumerates every interpreter-native Python builtin function.
6///
7/// Listed alphabetically per <https://docs.python.org/3/library/functions.html>
8/// Commented-out variants are not yet implemented.
9///
10/// Note: Type constructors are handled by the `Type` enum, not here.
11///
12/// Uses strum derives for automatic `Display`, `FromStr`, and `IntoStaticStr` implementations.
13/// All variants serialize to lowercase (e.g., `Print` -> "print").
14#[derive(
15 Debug,
16 Clone,
17 Copy,
18 Display,
19 EnumString,
20 FromRepr,
21 IntoStaticStr,
22 VariantNames,
23 PartialEq,
24 Eq,
25 Hash,
26 serde::Serialize,
27 serde::Deserialize,
28)]
29// `use_phf` while still below the ~100-variant threshold: it breaks even now and the enum keeps growing.
30#[strum(serialize_all = "lowercase", use_phf)]
31#[serde(rename_all = "lowercase")]
32#[repr(u8)]
33pub enum BuiltinsFunctions {
34 Abs,
35 // Aiter,
36 All,
37 // Anext,
38 Any,
39 // Ascii,
40 Bin,
41 // bool - handled by Type enum
42 // Breakpoint,
43 // bytearray - handled by Type enum
44 // bytes - handled by Type enum
45 // Callable,
46 Chr,
47 // Classmethod,
48 // Compile,
49 // complex - handled by Type enum
50 // Delattr,
51 // dict - handled by Type enum
52 // Dir,
53 Divmod,
54 Enumerate,
55 Filter,
56 // float - handled by Type enum
57 // Format - appended below
58 // frozenset - handled by Type enum
59 Getattr,
60 // Globals,
61 Hasattr,
62 Hash,
63 // Help,
64 Hex,
65 Id,
66 // Input,
67 // int - handled by Type enum
68 Isinstance,
69 // Issubclass,
70 // Iter - handled by Type enum
71 Len,
72 // list - handled by Type enum
73 Map,
74 Max,
75 // memoryview - handled by Type enum
76 Min,
77 Next,
78 // object - handled by Type enum
79 Oct,
80 Open,
81 Ord,
82 Pow,
83 Print,
84 // Property,
85 // range - handled by Type enum
86 Repr,
87 Reversed,
88 Round,
89 // set - handled by Type enum
90 Setattr,
91 // Slice,
92 Sorted,
93 // Staticmethod,
94 // str - handled by Type enum
95 Sum,
96 // Super,
97 // tuple - handled by Type enum
98 Type,
99 // Vars,
100 Zip,
101 // __import__ - not planned
102 // Appended out of alphabetical order: the discriminant is emitted as a
103 // bytecode operand, so this list is append-only.
104 /// `object.__setattr__(obj, name, value)` — the write that bypasses a
105 /// class's attribute hooks, reached only through `object`. Its name is not
106 /// an identifier, so it can never resolve as a bare global.
107 ///
108 /// The first variant whose name is not its lowercased identifier, so it
109 /// needs both renames: serde and strum each carry the name across a
110 /// different boundary (JSON vs. `Display`/`FromStr`) and must agree.
111 #[strum(serialize = "object.__setattr__")]
112 #[serde(rename = "object.__setattr__")]
113 ObjectSetattr,
114 /// `format(value, format_spec='')`, appended after [`Self::ObjectSetattr`].
115 Format,
116 /// `eval(source, /, globals=None, locals=None)`, appended after [`Self::Format`].
117 Eval,
118 /// `exec(source, /, globals=None, locals=None, *, closure=None)`, appended after [`Self::Eval`].
119 Exec,
120 /// `locals()`, appended after [`Self::Exec`].
121 Locals,
122}