Merge pull request #2485 from mhils/silent-option-redeclaration

Make option redeclaration silent if signature is the same
This commit is contained in:
Maximilian Hils 2017-07-30 03:47:25 +02:00 committed by GitHub
commit f844c68e2e
2 changed files with 20 additions and 1 deletions

View file

@ -86,7 +86,18 @@ class Loader:
choices: typing.Optional[typing.Sequence[str]] = None
) -> None:
if name in self.master.options:
ctx.log.warn("Over-riding existing option %s" % name)
existing = self.master.options._options[name]
same_signature = (
existing.name == name and
existing.typespec == typespec and
existing.default == default and
existing.help == help and
existing.choices == choices
)
if same_signature:
return
else:
ctx.log.warn("Over-riding existing option %s" % name)
self.master.options.add_option(
name,
typespec,

View file

@ -91,7 +91,15 @@ def test_loader():
with taddons.context() as tctx:
l = addonmanager.Loader(tctx.master)
l.add_option("custom_option", bool, False, "help")
assert "custom_option" in l.master.options
# calling this again with the same signature is a no-op.
l.add_option("custom_option", bool, False, "help")
assert not tctx.master.has_log("Over-riding existing option")
# a different signature should emit a warning though.
l.add_option("custom_option", bool, True, "help")
assert tctx.master.has_log("Over-riding existing option")
def cmd(a: str) -> str:
return "foo"