summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Whetter <ashley@awhetter.co.uk>2017-07-26 04:40:49 +0100
committerAshley Whetter <ashley@awhetter.co.uk>2019-02-09 13:22:36 -0800
commitdf0551ab02293aae586c3b75a0e1f8b176a7cc79 (patch)
tree264806074d70c498b71227289ad1cac6417d7951
parent278ab731a3f3e89c966d80c3b05554426183e863 (diff)
downloadpylint-git-df0551ab02293aae586c3b75a0e1f8b176a7cc79.tar.gz
Fixed option callbacks not getting run
-rw-r--r--pylint/config.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/pylint/config.py b/pylint/config.py
index ae1d87fd1..a446171e8 100644
--- a/pylint/config.py
+++ b/pylint/config.py
@@ -581,16 +581,20 @@ Please report bugs on the project\'s mailing list:
class OptionsManagerMixIn:
"""Handle configuration from both a configuration file and command line options"""
- class NullAction(argparse.Action):
+ class CallbackAction(argparse.Action):
"""Doesn't store the value on the config."""
- def __init__(self, *args, nargs=0, **kwargs):
- super(OptionsManagerMixIn.NullAction, self).__init__(
+ def __init__(self, *args, nargs=None, **kwargs):
+ nargs = nargs or int("metavar" in kwargs)
+ super(OptionsManagerMixIn.CallbackAction, self).__init__(
*args, nargs=nargs, **kwargs
)
- def __call__(self, *args, **kwargs):
- pass
+ def __call__(self, parser, namespace, values, option_string):
+ # If no value was passed, argparse didn't call the callback via
+ # `type`, so we need to do it ourselves.
+ if not self.nargs and callable(self.type):
+ self.type(self, option_string, values, parser)
def __init__(self, usage, config_file=None, version=None):
self.config_file = config_file
@@ -693,7 +697,7 @@ class OptionsManagerMixIn:
self._nocallback_options[provider] = opt
if optdict["action"] == "callback":
optdict["type"] = optdict["callback"]
- optdict["action"] = self.NullAction
+ optdict["action"] = self.CallbackAction
del optdict["callback"]
else:
callback = functools.partial(