Skip to content

Commit 1b6f505

Browse files
committed
Fix the error_on_duplicate issue
1 parent ffbf6c5 commit 1b6f505

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎paths_cli/compiling/core.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def __call__(self, dct):
244244

245245
class Compiler:
246246
"""Generic compile class; instances for each category"""
247-
error_on_duplicate = False # TODO: temporary
247+
# error_on_duplicate = False # TODO: temporary
248+
error_on_duplicate = True
248249
def __init__(self, type_dispatch, label):
249250
if type_dispatch is None:
250251
type_dispatch = {}
@@ -283,12 +284,12 @@ def register_object(self, obj, name):
283284

284285
def register_builder(self, builder, name):
285286
if name in self.type_dispatch:
287+
if self.type_dispatch[name] is builder:
288+
return # nothing to do here!
286289
msg = (f"'{name}' is already registered "
287290
f"with {self.label}")
288291
if self.error_on_duplicate:
289292
raise RuntimeError(msg)
290-
else:
291-
warnings.warn(msg)
292293
else:
293294
self.type_dispatch[name] = builder
294295

‎paths_cli/compiling/networks.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def tis_trans_info(dct):
6666
name='tis'
6767
)
6868

69-
# old names not yet replaced in testing
69+
# old names not yet replaced in testing THESE ARE WHY WE'RE DOUBLING! GET
70+
# RID OF THEM! (also, use an is-check)
7071
build_tps_network = TPS_NETWORK_PLUGIN
7172
build_mistis_network = MISTIS_NETWORK_PLUGIN
7273
build_tis_network = TIS_NETWORK_PLUGIN

‎paths_cli/tests/compiling/test_core.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ def test_register_builder_duplicate(self):
285285
# if an attempt is made to registered a builder with a name that is
286286
# already in use, a RuntimeError is raised
287287
orig = self.compiler.type_dispatch['foo']
288-
# TODO: this should be an error; need to figure out how to avoid
289-
# duplication
290-
# with pytest.raises(RuntimeError, match="already registered"):
291-
with pytest.warns(UserWarning, match="already registered"):
288+
with pytest.raises(RuntimeError, match="already registered"):
292289
self.compiler.register_builder(lambda dct: 10, 'foo')
293290

294291
assert self.compiler.type_dispatch['foo'] is orig

0 commit comments

Comments
 (0)