Skip to content

Commit 853ef2e

Browse files
committed
starting codegen_py: naming
1 parent be5bebb commit 853ef2e

1 file changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Python-specific naming utilities and sanitization.
3+
4+
Handles Python reserved words, builtins, and naming conventions.
5+
"""
6+
7+
from ...core.naming import NameSanitizer
8+
9+
10+
# Python reserved keywords
11+
PYTHON_RESERVED_WORDS = {
12+
"False",
13+
"None",
14+
"True",
15+
"and",
16+
"as",
17+
"assert",
18+
"async",
19+
"await",
20+
"break",
21+
"class",
22+
"continue",
23+
"def",
24+
"del",
25+
"elif",
26+
"else",
27+
"except",
28+
"finally",
29+
"for",
30+
"from",
31+
"global",
32+
"if",
33+
"import",
34+
"in",
35+
"is",
36+
"lambda",
37+
"nonlocal",
38+
"not",
39+
"or",
40+
"pass",
41+
"raise",
42+
"return",
43+
"try",
44+
"while",
45+
"with",
46+
"yield",
47+
}
48+
49+
# Python built-in types and functions
50+
PYTHON_BUILTIN_TYPES = {
51+
# Types
52+
"int",
53+
"float",
54+
"str",
55+
"bool",
56+
"list",
57+
"dict",
58+
"set",
59+
"tuple",
60+
"bytes",
61+
"bytearray",
62+
"frozenset",
63+
"range",
64+
"object",
65+
"type",
66+
"complex",
67+
"memoryview",
68+
# Special attributes
69+
"property",
70+
"staticmethod",
71+
"classmethod",
72+
"super",
73+
# Common functions
74+
"len",
75+
"print",
76+
"input",
77+
"open",
78+
"all",
79+
"any",
80+
"abs",
81+
"min",
82+
"max",
83+
"sum",
84+
"sorted",
85+
"reversed",
86+
"enumerate",
87+
"zip",
88+
"map",
89+
"filter",
90+
"isinstance",
91+
"issubclass",
92+
"hasattr",
93+
"getattr",
94+
"setattr",
95+
"delattr",
96+
"dir",
97+
"vars",
98+
"id",
99+
"hash",
100+
"repr",
101+
"str",
102+
"format",
103+
"iter",
104+
"next",
105+
"slice",
106+
"callable",
107+
# Exceptions
108+
"Exception",
109+
"BaseException",
110+
"ValueError",
111+
"TypeError",
112+
"KeyError",
113+
"AttributeError",
114+
"IndexError",
115+
"RuntimeError",
116+
"NotImplementedError",
117+
"StopIteration",
118+
}
119+
120+
121+
def create_python_sanitizer() -> NameSanitizer:
122+
"""Create a name sanitizer configured for Python."""
123+
return NameSanitizer(PYTHON_RESERVED_WORDS, PYTHON_BUILTIN_TYPES)

0 commit comments

Comments
 (0)