Skip to content

Commit f51c0f4

Browse files
committed
Pull out a helper for checking whether a candidate name is allowed
This will make the following changes clearer.
1 parent 19aa241 commit f51c0f4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/fluent_compiler/codegen.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,21 @@ def _add(final):
160160
# take into account parent scope when assigning names.
161161

162162
used = self.all_reserved_names()
163+
163164
# We need to also protect against using keywords ('class', 'def' etc.)
164165
# i.e. count all keywords as 'used'.
165166
# However, some builtins are also keywords (e.g. 'None'), and so
166167
# if a builtin is being reserved, don't check against the keyword list
167168
if not is_builtin:
168169
used = used | set(keyword.kwlist)
169-
while attempt in used:
170+
171+
def _is_name_allowed(name: str) -> bool:
172+
return name not in used
173+
174+
while not _is_name_allowed(attempt):
170175
attempt = cleaned + str(count)
171176
count += 1
177+
172178
return _add(attempt)
173179

174180
def reserve_function_arg_name(self, name):

0 commit comments

Comments
 (0)