Skip to content

Commit 19309c8

Browse files
committed
Use keyword.iskeyword rather than expanding the set of reserved names
Prior to this change, if we were checking whether a non-builtin name was allowed, we would expand the set of reserved names to include all keywords. This change switches to using the iskeyword function instead, which will allow us to stop using the set of reserved names altogether in a future commit.
1 parent f51c0f4 commit 19309c8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/fluent_compiler/codegen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ def _add(final):
161161

162162
used = self.all_reserved_names()
163163

164-
# We need to also protect against using keywords ('class', 'def' etc.)
165-
# i.e. count all keywords as 'used'.
166-
# However, some builtins are also keywords (e.g. 'None'), and so
167-
# if a builtin is being reserved, don't check against the keyword list
168-
if not is_builtin:
169-
used = used | set(keyword.kwlist)
170-
171164
def _is_name_allowed(name: str) -> bool:
165+
# We need to also protect against using keywords ('class', 'def' etc.)
166+
# i.e. count all keywords as 'used'.
167+
# However, some builtins are also keywords (e.g. 'None'), and so
168+
# if a builtin is being reserved, don't check against the keyword list
169+
if (not is_builtin) and keyword.iskeyword(name):
170+
return False
171+
172172
return name not in used
173173

174174
while not _is_name_allowed(attempt):

0 commit comments

Comments
 (0)