Skip to content

Commit 760ef06

Browse files
committed
refuse to overwrite existing global names
1 parent d8bc751 commit 760ef06

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

abacus.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,19 @@ def command(*args):
106106
return command
107107

108108

109+
def _install_command(name, function):
110+
if name in globals():
111+
raise ValueError(f'duplicate name: {name}')
112+
globals()[name] = function
113+
__all__.append(name)
114+
115+
109116
def _install_commands():
110117
for name, aliases in _commands.items():
111-
globals()[name] = _make_command(name)
112-
__all__.append(name)
118+
new_command = _make_command(name)
119+
_install_command(name, new_command)
113120
for alias in aliases:
114-
globals()[alias] = globals()[name]
115-
__all__.append(alias)
121+
_install_command(alias, new_command)
116122

117123

118124
_install_commands()

0 commit comments

Comments
 (0)