Skip to content

Commit 4d8a515

Browse files
bpo-46541: Scan Fewer Files in generate_global_objects.py (gh-31364)
https://bugs.python.org/issue46541
1 parent 6c89589 commit 4d8a515

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

Tools/scripts/generate_global_objects.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,28 @@
100100
#######################################
101101
# helpers
102102

103+
def iter_files():
104+
for name in ('Modules', 'Objects', 'Parser', 'PC', 'Programs', 'Python'):
105+
root = os.path.join(ROOT, name)
106+
for dirname, _, files in os.walk(root):
107+
for name in files:
108+
if not name.endswith(('.c', '.h')):
109+
continue
110+
yield os.path.join(dirname, name)
111+
112+
103113
def iter_global_strings():
104114
id_regex = re.compile(r'\b_Py_ID\((\w+)\)')
105115
str_regex = re.compile(r'\b_Py_DECLARE_STR\((\w+), "(.*?)"\)')
106-
for dirname, _, files in os.walk(ROOT):
107-
if os.path.relpath(dirname, ROOT).startswith('Include'):
108-
continue
109-
for name in files:
110-
if not name.endswith(('.c', '.h')):
111-
continue
112-
filename = os.path.join(dirname, name)
113-
with open(os.path.join(filename), encoding='utf-8') as infile:
114-
for lno, line in enumerate(infile, 1):
115-
for m in id_regex.finditer(line):
116-
identifier, = m.groups()
117-
yield identifier, None, filename, lno, line
118-
for m in str_regex.finditer(line):
119-
varname, string = m.groups()
120-
yield varname, string, filename, lno, line
116+
for filename in iter_files():
117+
with open(filename, encoding='utf-8') as infile:
118+
for lno, line in enumerate(infile, 1):
119+
for m in id_regex.finditer(line):
120+
identifier, = m.groups()
121+
yield identifier, None, filename, lno, line
122+
for m in str_regex.finditer(line):
123+
varname, string = m.groups()
124+
yield varname, string, filename, lno, line
121125

122126
def iter_to_marker(lines, marker):
123127
for line in lines:

0 commit comments

Comments
 (0)