diff options
author | Brett Cannon <brett@python.org> | 2014-08-29 11:16:29 -0400 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2014-08-29 11:16:29 -0400 |
commit | 131810f8df6431ffef5d0cf345d67aeec7c3c605 (patch) | |
tree | d4c1219e564ccffc8feeb3b42785038a47cc14e6 /checkers/classes.py | |
parent | 2995e293950edc39b0466d1274affc1136c066c8 (diff) | |
download | pylint-131810f8df6431ffef5d0cf345d67aeec7c3c605.tar.gz |
Modernize to the point of working for Python 2.7 still
Diffstat (limited to 'checkers/classes.py')
-rw-r--r-- | checkers/classes.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/checkers/classes.py b/checkers/classes.py index aa05558..d9b7581 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -28,6 +28,7 @@ from pylint.checkers import BaseChecker from pylint.checkers.utils import ( PYMETHODS, overrides_a_method, check_messages, is_attr_private, is_attr_protected, node_frame_class, safe_infer, is_builtin_object) +import six if sys.version_info >= (3, 0): NEXT_METHOD = '__next__' @@ -298,7 +299,7 @@ a metaclass class method.'} return defining_methods = self.config.defining_attr_methods current_module = cnode.root() - for attr, nodes in cnode.instance_attrs.iteritems(): + for attr, nodes in six.iteritems(cnode.instance_attrs): # skip nodes which are not in the current module and it may screw up # the output, while it's not worth it nodes = [n for n in nodes if not @@ -612,7 +613,7 @@ a metaclass class method.'} def _check_accessed_members(self, node, accessed): """check that accessed members are defined""" # XXX refactor, probably much simpler now that E0201 is in type checker - for attr, nodes in accessed.iteritems(): + for attr, nodes in six.iteritems(accessed): # deactivate "except doesn't do anything", that's expected # pylint: disable=W0704 try: @@ -624,7 +625,7 @@ a metaclass class method.'} pass # is it an instance attribute of a parent class ? try: - node.instance_attr_ancestors(attr).next() + next(node.instance_attr_ancestors(attr)) # yes, stop here continue except StopIteration: @@ -816,7 +817,7 @@ a metaclass class method.'} expr.expr.func.name == 'super': return try: - klass = expr.expr.infer().next() + klass = next(expr.expr.infer()) if klass is YES: continue # The infered klass can be super(), which was @@ -838,7 +839,7 @@ a metaclass class method.'} node=expr, args=klass.name) except astroid.InferenceError: continue - for klass, method in not_called_yet.iteritems(): + for klass, method in six.iteritems(not_called_yet): if klass.name == 'object' or method.parent.name == 'object': continue self.add_message('super-init-not-called', args=klass.name, node=node) @@ -880,7 +881,7 @@ def _ancestors_to_call(klass_node, method='__init__'): to_call = {} for base_node in klass_node.ancestors(recurs=False): try: - to_call[base_node] = base_node.igetattr(method).next() + to_call[base_node] = next(base_node.igetattr(method)) except astroid.InferenceError: continue return to_call |