mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
make option redeclaration silent if signature is the same
This commit is contained in:
parent
ecc01b0f02
commit
6a41122990
@ -86,6 +86,17 @@ class Loader:
|
||||
choices: typing.Optional[typing.Sequence[str]] = None
|
||||
) -> None:
|
||||
if name in self.master.options:
|
||||
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,
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user