diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-20 07:31:42 -0500 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2018-10-20 12:37:14 -0500 |
| commit | c58a4662d8920cf70ea688edd9eaf9d783a856a7 (patch) | |
| tree | 6dda552de1b7250ccd1347a7ebc62dc69b9ff0c0 /src/flake8/plugins | |
| parent | a2b7a7e4c590d73acc77a17ff8b0450e3b9b81d8 (diff) | |
| download | flake8-c58a4662d8920cf70ea688edd9eaf9d783a856a7.tar.gz | |
Use black to reformat Flake8
Instead of just using Flake8 and pylint to keep Flake8 clean, let's also
use black to make it less manual for clean-up.
Diffstat (limited to 'src/flake8/plugins')
| -rw-r--r-- | src/flake8/plugins/_trie.py | 8 | ||||
| -rw-r--r-- | src/flake8/plugins/manager.py | 109 | ||||
| -rw-r--r-- | src/flake8/plugins/notifier.py | 2 | ||||
| -rw-r--r-- | src/flake8/plugins/pyflakes.py | 154 |
4 files changed, 150 insertions, 123 deletions
diff --git a/src/flake8/plugins/_trie.py b/src/flake8/plugins/_trie.py index 17c226f..9a50b45 100644 --- a/src/flake8/plugins/_trie.py +++ b/src/flake8/plugins/_trie.py @@ -1,11 +1,11 @@ """Independent implementation of a Trie tree.""" -__all__ = ('Trie', 'TrieNode') +__all__ = ("Trie", "TrieNode") def _iterate_stringlike_objects(string): for i in range(len(string)): - yield string[i:i + 1] + yield string[i : i + 1] class Trie(object): @@ -57,9 +57,7 @@ class TrieNode(object): def __repr__(self): """Generate an easy to read representation of the node.""" - return 'TrieNode(prefix={0}, data={1})'.format( - self.prefix, self.data - ) + return "TrieNode(prefix={0}, data={1})".format(self.prefix, self.data) def find_prefix(self, prefix): """Find the prefix in the children of this node. diff --git a/src/flake8/plugins/manager.py b/src/flake8/plugins/manager.py index 503dfbb..1b9005e 100644 --- a/src/flake8/plugins/manager.py +++ b/src/flake8/plugins/manager.py @@ -11,11 +11,11 @@ from flake8.plugins import notifier LOG = logging.getLogger(__name__) __all__ = ( - 'Checkers', - 'Listeners', - 'Plugin', - 'PluginManager', - 'ReportFormatters', + "Checkers", + "Listeners", + "Plugin", + "PluginManager", + "ReportFormatters", ) NO_GROUP_FOUND = object() @@ -55,11 +55,11 @@ class Plugin(object): def to_dictionary(self): """Convert this plugin to a dictionary.""" return { - 'name': self.name, - 'parameters': self.parameters, - 'parameter_names': self.parameter_names, - 'plugin': self.plugin, - 'plugin_name': self.plugin_name, + "name": self.name, + "parameters": self.parameters, + "parameter_names": self.parameter_names, + "plugin": self.plugin, + "plugin_name": self.plugin_name, } def is_in_a_group(self): @@ -75,7 +75,7 @@ class Plugin(object): def group(self): """Find and parse the group the plugin is in.""" if self._group is None: - name = self.name.split('.', 1) + name = self.name.split(".", 1) if len(name) > 1: self._group = name[0] else: @@ -132,7 +132,7 @@ class Plugin(object): @property def off_by_default(self): """Return whether the plugin is ignored by default.""" - return getattr(self.plugin, 'off_by_default', False) + return getattr(self.plugin, "off_by_default", False) def execute(self, *args, **kwargs): r"""Call the plugin with \*args and \*\*kwargs.""" @@ -140,22 +140,21 @@ class Plugin(object): def _load(self, verify_requirements): # Avoid relying on hasattr() here. - resolve = getattr(self.entry_point, 'resolve', None) - require = getattr(self.entry_point, 'require', None) + resolve = getattr(self.entry_point, "resolve", None) + require = getattr(self.entry_point, "require", None) if resolve and require: if verify_requirements: - LOG.debug('Verifying plugin "%s"\'s requirements.', - self.name) + LOG.debug('Verifying plugin "%s"\'s requirements.', self.name) require() self._plugin = resolve() else: - self._plugin = self.entry_point.load( - require=verify_requirements - ) + self._plugin = self.entry_point.load(require=verify_requirements) if not callable(self._plugin): - msg = ('Plugin %r is not a callable. It might be written for an' - ' older version of flake8 and might not work with this' - ' version' % self._plugin) + msg = ( + "Plugin %r is not a callable. It might be written for an" + " older version of flake8 and might not work with this" + " version" % self._plugin + ) LOG.critical(msg) raise TypeError(msg) @@ -179,8 +178,7 @@ class Plugin(object): except Exception as load_exception: LOG.exception(load_exception) failed_to_load = exceptions.FailedToLoadPlugin( - plugin=self, - exception=load_exception, + plugin=self, exception=load_exception ) LOG.critical(str(failed_to_load)) raise failed_to_load @@ -194,8 +192,11 @@ class Plugin(object): try: options.ignore.remove(self.name) except (ValueError, KeyError): - LOG.debug('Attempted to remove %s from the ignore list but it was ' - 'not a member of the list.', self.name) + LOG.debug( + "Attempted to remove %s from the ignore list but it was " + "not a member of the list.", + self.name, + ) def disable(self, optmanager): """Add the plugin name to the default ignore list.""" @@ -203,7 +204,7 @@ class Plugin(object): def provide_options(self, optmanager, options, extra_args): """Pass the parsed options and extra arguments to the plugin.""" - parse_options = getattr(self.plugin, 'parse_options', None) + parse_options = getattr(self.plugin, "parse_options", None) if parse_options is not None: LOG.debug('Providing options to plugin "%s".', self.name) try: @@ -224,11 +225,12 @@ class Plugin(object): :returns: Nothing """ - add_options = getattr(self.plugin, 'add_options', None) + add_options = getattr(self.plugin, "add_options", None) if add_options is not None: LOG.debug( 'Registering options from plugin "%s" on OptionManager %r', - self.name, optmanager + self.name, + optmanager, ) add_options(optmanager) @@ -239,8 +241,9 @@ class Plugin(object): class PluginManager(object): # pylint: disable=too-few-public-methods """Find and manage plugins consistently.""" - def __init__(self, namespace, - verify_requirements=False, local_plugins=None): + def __init__( + self, namespace, verify_requirements=False, local_plugins=None + ): """Initialize the manager. :param str namespace: @@ -348,7 +351,7 @@ def version_for(plugin): except ImportError: return None - return getattr(module, '__version__', None) + return getattr(module, "__version__", None) class PluginTypeManager(object): @@ -363,7 +366,8 @@ class PluginTypeManager(object): Plugins from config file instead of entry-points """ self.manager = PluginManager( - self.namespace, local_plugins=local_plugins) + self.namespace, local_plugins=local_plugins + ) self.plugins_loaded = False def __contains__(self, name): @@ -406,9 +410,11 @@ class PluginTypeManager(object): def _generate_call_function(method_name, optmanager, *args, **kwargs): def generated_function(plugin): # noqa: D105 method = getattr(plugin, method_name, None) - if (method is not None and - isinstance(method, collections.Callable)): + if method is not None and isinstance( + method, collections.Callable + ): return method(optmanager, *args, **kwargs) + return generated_function def load_plugins(self): @@ -435,7 +441,7 @@ class PluginTypeManager(object): """Register all of the checkers' options to the OptionManager.""" self.load_plugins() call_register_options = self._generate_call_function( - 'register_options', optmanager, + "register_options", optmanager ) list(self.manager.map(call_register_options)) @@ -443,7 +449,7 @@ class PluginTypeManager(object): def provide_options(self, optmanager, options, extra_args): """Provide parsed options and extra arguments to the plugins.""" call_provide_options = self._generate_call_function( - 'provide_options', optmanager, options, extra_args, + "provide_options", optmanager, options, extra_args ) list(self.manager.map(call_provide_options)) @@ -470,7 +476,7 @@ class NotifierBuilderMixin(object): # pylint: disable=too-few-public-methods class Checkers(PluginTypeManager): """All of the checkers registered through entry-points or config.""" - namespace = 'flake8.extension' + namespace = "flake8.extension" def checks_expecting(self, argument_name): """Retrieve checks that expect an argument with the specified name. @@ -484,14 +490,15 @@ class Checkers(PluginTypeManager): def to_dictionary(self): """Return a dictionary of AST and line-based plugins.""" return { - 'ast_plugins': [ + "ast_plugins": [ plugin.to_dictionary() for plugin in self.ast_plugins ], - 'logical_line_plugins': [ + "logical_line_plugins": [ plugin.to_dictionary() for plugin in self.logical_line_plugins ], - 'physical_line_plugins': [ - plugin.to_dictionary() for plugin in self.physical_line_plugins + "physical_line_plugins": [ + plugin.to_dictionary() + for plugin in self.physical_line_plugins ], } @@ -508,7 +515,7 @@ class Checkers(PluginTypeManager): # function to map over the plugins. self.load_plugins() call_register_options = self._generate_call_function( - 'register_options', optmanager, + "register_options", optmanager ) def register_and_enable(plugin): @@ -521,27 +528,27 @@ class Checkers(PluginTypeManager): @property def ast_plugins(self): """List of plugins that expect the AST tree.""" - plugins = getattr(self, '_ast_plugins', []) + plugins = getattr(self, "_ast_plugins", []) if not plugins: - plugins = list(self.checks_expecting('tree')) + plugins = list(self.checks_expecting("tree")) self._ast_plugins = plugins return plugins @property def logical_line_plugins(self): """List of plugins that expect the logical lines.""" - plugins = getattr(self, '_logical_line_plugins', []) + plugins = getattr(self, "_logical_line_plugins", []) if not plugins: - plugins = list(self.checks_expecting('logical_line')) + plugins = list(self.checks_expecting("logical_line")) self._logical_line_plugins = plugins return plugins @property def physical_line_plugins(self): """List of plugins that expect the physical lines.""" - plugins = getattr(self, '_physical_line_plugins', []) + plugins = getattr(self, "_physical_line_plugins", []) if not plugins: - plugins = list(self.checks_expecting('physical_line')) + plugins = list(self.checks_expecting("physical_line")) self._physical_line_plugins = plugins return plugins @@ -549,10 +556,10 @@ class Checkers(PluginTypeManager): class Listeners(PluginTypeManager, NotifierBuilderMixin): """All of the listeners registered through entry-points or config.""" - namespace = 'flake8.listen' + namespace = "flake8.listen" class ReportFormatters(PluginTypeManager): """All of the report formatters registered through entry-points/config.""" - namespace = 'flake8.report' + namespace = "flake8.report" diff --git a/src/flake8/plugins/notifier.py b/src/flake8/plugins/notifier.py index dc255c4..9efccd4 100644 --- a/src/flake8/plugins/notifier.py +++ b/src/flake8/plugins/notifier.py @@ -31,7 +31,7 @@ class Notifier(object): path = error_code while path: node = self.listeners.find(path) - listeners = getattr(node, 'data', []) + listeners = getattr(node, "data", []) for listener in listeners: yield listener path = path[:-1] diff --git a/src/flake8/plugins/pyflakes.py b/src/flake8/plugins/pyflakes.py index 9ef9e93..e2ef2c3 100644 --- a/src/flake8/plugins/pyflakes.py +++ b/src/flake8/plugins/pyflakes.py @@ -18,35 +18,35 @@ from flake8 import utils FLAKE8_PYFLAKES_CODES = { - 'UnusedImport': 'F401', - 'ImportShadowedByLoopVar': 'F402', - 'ImportStarUsed': 'F403', - 'LateFutureImport': 'F404', - 'ImportStarUsage': 'F405', - 'ImportStarNotPermitted': 'F406', - 'FutureFeatureNotDefined': 'F407', - 'MultiValueRepeatedKeyLiteral': 'F601', - 'MultiValueRepeatedKeyVariable': 'F602', - 'TooManyExpressionsInStarredAssignment': 'F621', - 'TwoStarredExpressions': 'F622', - 'AssertTuple': 'F631', - 'BreakOutsideLoop': 'F701', - 'ContinueOutsideLoop': 'F702', - 'ContinueInFinally': 'F703', - 'YieldOutsideFunction': 'F704', - 'ReturnWithArgsInsideGenerator': 'F705', - 'ReturnOutsideFunction': 'F706', - 'DefaultExceptNotLast': 'F707', - 'DoctestSyntaxError': 'F721', - 'ForwardAnnotationSyntaxError': 'F722', - 'RedefinedWhileUnused': 'F811', - 'RedefinedInListComp': 'F812', - 'UndefinedName': 'F821', - 'UndefinedExport': 'F822', - 'UndefinedLocal': 'F823', - 'DuplicateArgument': 'F831', - 'UnusedVariable': 'F841', - 'RaiseNotImplemented': 'F901', + "UnusedImport": "F401", + "ImportShadowedByLoopVar": "F402", + "ImportStarUsed": "F403", + "LateFutureImport": "F404", + "ImportStarUsage": "F405", + "ImportStarNotPermitted": "F406", + "FutureFeatureNotDefined": "F407", + "MultiValueRepeatedKeyLiteral": "F601", + "MultiValueRepeatedKeyVariable": "F602", + "TooManyExpressionsInStarredAssignment": "F621", + "TwoStarredExpressions": "F622", + "AssertTuple": "F631", + "BreakOutsideLoop": "F701", + "ContinueOutsideLoop": "F702", + "ContinueInFinally": "F703", + "YieldOutsideFunction": "F704", + "ReturnWithArgsInsideGenerator": "F705", + "ReturnOutsideFunction": "F706", + "DefaultExceptNotLast": "F707", + "DoctestSyntaxError": "F721", + "ForwardAnnotationSyntaxError": "F722", + "RedefinedWhileUnused": "F811", + "RedefinedInListComp": "F812", + "UndefinedName": "F821", + "UndefinedExport": "F822", + "UndefinedLocal": "F823", + "DuplicateArgument": "F831", + "UnusedVariable": "F841", + "RaiseNotImplemented": "F901", } @@ -54,8 +54,9 @@ def patch_pyflakes(): """Add error codes to Pyflakes messages.""" for name, obj in vars(pyflakes.messages).items(): if name[0].isupper() and obj.message: - obj.flake8_msg = '%s %s' % ( - FLAKE8_PYFLAKES_CODES.get(name, 'F999'), obj.message + obj.flake8_msg = "%s %s" % ( + FLAKE8_PYFLAKES_CODES.get(name, "F999"), + obj.message, ) @@ -65,7 +66,7 @@ patch_pyflakes() class FlakesChecker(pyflakes.checker.Checker): """Subclass the Pyflakes checker to conform with the flake8 API.""" - name = 'pyflakes' + name = "pyflakes" version = pyflakes.__version__ with_doctest = False include_in_doctest = [] @@ -75,48 +76,65 @@ class FlakesChecker(pyflakes.checker.Checker): """Initialize the PyFlakes plugin with an AST tree and filename.""" filename = utils.normalize_paths(filename)[0] with_doctest = self.with_doctest - included_by = [include for include in self.include_in_doctest - if include != '' and filename.startswith(include)] + included_by = [ + include + for include in self.include_in_doctest + if include != "" and filename.startswith(include) + ] if included_by: with_doctest = True for exclude in self.exclude_from_doctest: - if exclude != '' and filename.startswith(exclude): + if exclude != "" and filename.startswith(exclude): with_doctest = False - overlaped_by = [include for include in included_by - if include.startswith(exclude)] + overlaped_by = [ + include + for include in included_by + if include.startswith(exclude) + ] if overlaped_by: with_doctest = True - super(FlakesChecker, self).__init__(tree, filename, - withDoctest=with_doctest) + super(FlakesChecker, self).__init__( + tree, filename, withDoctest=with_doctest + ) @classmethod def add_options(cls, parser): """Register options for PyFlakes on the Flake8 OptionManager.""" parser.add_option( - '--builtins', parse_from_config=True, comma_separated_list=True, + "--builtins", + parse_from_config=True, + comma_separated_list=True, help="define more built-ins, comma separated", ) parser.add_option( - '--doctests', default=False, action='store_true', + "--doctests", + default=False, + action="store_true", parse_from_config=True, help="check syntax of the doctests", ) parser.add_option( - '--include-in-doctest', default='', - dest='include_in_doctest', parse_from_config=True, - comma_separated_list=True, normalize_paths=True, - help='Run doctests only on these files', - type='string', + "--include-in-doctest", + default="", + dest="include_in_doctest", + parse_from_config=True, + comma_separated_list=True, + normalize_paths=True, + help="Run doctests only on these files", + type="string", ) parser.add_option( - '--exclude-from-doctest', default='', - dest='exclude_from_doctest', parse_from_config=True, - comma_separated_list=True, normalize_paths=True, - help='Skip these files when running doctests', - type='string', + "--exclude-from-doctest", + default="", + dest="exclude_from_doctest", + parse_from_config=True, + comma_separated_list=True, + normalize_paths=True, + help="Skip these files when running doctests", + type="string", ) @classmethod @@ -128,20 +146,20 @@ class FlakesChecker(pyflakes.checker.Checker): included_files = [] for included_file in options.include_in_doctest: - if included_file == '': + if included_file == "": continue - if not included_file.startswith((os.sep, './', '~/')): - included_files.append('./' + included_file) + if not included_file.startswith((os.sep, "./", "~/")): + included_files.append("./" + included_file) else: included_files.append(included_file) cls.include_in_doctest = utils.normalize_paths(included_files) excluded_files = [] for excluded_file in options.exclude_from_doctest: - if excluded_file == '': + if excluded_file == "": continue - if not excluded_file.startswith((os.sep, './', '~/')): - excluded_files.append('./' + excluded_file) + if not excluded_file.startswith((os.sep, "./", "~/")): + excluded_files.append("./" + excluded_file) else: excluded_files.append(excluded_file) cls.exclude_from_doctest = utils.normalize_paths(excluded_files) @@ -150,16 +168,20 @@ class FlakesChecker(pyflakes.checker.Checker): cls.exclude_from_doctest ) if inc_exc: - raise ValueError('"%s" was specified in both the ' - 'include-in-doctest and exclude-from-doctest ' - 'options. You are not allowed to specify it in ' - 'both for doctesting.' % inc_exc) + raise ValueError( + '"%s" was specified in both the ' + "include-in-doctest and exclude-from-doctest " + "options. You are not allowed to specify it in " + "both for doctesting." % inc_exc + ) def run(self): """Run the plugin.""" for message in self.messages: - col = getattr(message, 'col', 0) - yield (message.lineno, - col, - (message.flake8_msg % message.message_args), - message.__class__) + col = getattr(message, "col", 0) + yield ( + message.lineno, + col, + (message.flake8_msg % message.message_args), + message.__class__, + ) |
