Skip to content

Commit 9151edc

Browse files
committed
Replace uses of all_reserved_names with is_name_reserved
1 parent 498cbb6 commit 9151edc

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/fluent_compiler/codegen.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _add(final):
170170
if requested in self.function_arg_reserved_names():
171171
assert requested not in self.names_in_use()
172172
return _add(requested)
173-
if requested in self.all_reserved_names():
173+
if self.is_name_reserved(requested):
174174
raise AssertionError(f"Cannot use '{requested}' as argument name as it is already in use")
175175

176176
cleaned = cleanup_name(requested)
@@ -180,8 +180,6 @@ def _add(final):
180180
# To avoid shadowing of global names in local scope, we
181181
# take into account parent scope when assigning names.
182182

183-
used = self.all_reserved_names()
184-
185183
def _is_name_allowed(name: str) -> bool:
186184
# We need to also protect against using keywords ('class', 'def' etc.)
187185
# i.e. count all keywords as 'used'.
@@ -190,7 +188,7 @@ def _is_name_allowed(name: str) -> bool:
190188
if (not is_builtin) and keyword.iskeyword(name):
191189
return False
192190

193-
return name not in used
191+
return not self.is_name_reserved(name)
194192

195193
while not _is_name_allowed(attempt):
196194
attempt = cleaned + str(count)
@@ -207,7 +205,7 @@ def reserve_function_arg_name(self, name):
207205
# To keep things simple, and the generated code predictable, we reserve
208206
# names for all function arguments in a separate scope, and insist on
209207
# the exact names
210-
if name in self.all_reserved_names():
208+
if self.is_name_reserved(name):
211209
raise AssertionError(f"Can't reserve '{name}' as function arg name as it is already reserved")
212210
self._function_arg_reserved_names.add(name)
213211

tests/test_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_reserve_name_function_arg(self):
6565
scope.reserve_function_arg_name("arg_name")
6666
scope.reserve_name("myfunc")
6767
func = codegen.Function("myfunc", args=["arg_name"], parent_scope=scope)
68-
self.assertNotIn("arg_name2", func.all_reserved_names())
68+
self.assertFalse(func.is_name_reserved("arg_name2"))
6969

7070
def test_reserve_name_nested(self):
7171
parent = codegen.Scope()

0 commit comments

Comments
 (0)