From 4f2e84100881fd39c0fe6e997f769730b4d32450 Mon Sep 17 00:00:00 2001 From: cpopa Date: Sun, 24 Aug 2014 22:03:35 +0300 Subject: Other backports from default. --- ChangeLog | 3 +++ checkers/classes.py | 6 ++++-- checkers/misc.py | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6fdba2..72d2cf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,9 @@ ChangeLog for Pylint Closes issue #311. * Fix a crash encountered when looking for attribute docstrings. + + * Fix a crash which ocurred while checking for 'method-hidden', + when the parent frame was something different than a function. 2014-07-26 -- 1.3.0 diff --git a/checkers/classes.py b/checkers/classes.py index 61769f2..232e130 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -344,9 +344,11 @@ a metaclass class method.'} try: overridden = klass.instance_attr(node.name)[0] # XXX overridden_frame = overridden.frame() - if overridden_frame.type == 'method': + if (isinstance(overridden_frame, astroid.Function) + and overridden_frame.type == 'method'): overridden_frame = overridden_frame.parent.frame() - if isinstance(overridden_frame, Class) and klass._is_subtype_of(overridden_frame.qname()): + if (isinstance(overridden_frame, Class) + and klass._is_subtype_of(overridden_frame.qname())): args = (overridden.root().name, overridden.fromlineno) self.add_message('method-hidden', args=args, node=node) except astroid.NotFoundError: diff --git a/checkers/misc.py b/checkers/misc.py index b53f882..b27b86a 100644 --- a/checkers/misc.py +++ b/checkers/misc.py @@ -54,6 +54,17 @@ class EncodingChecker(BaseChecker): 'separated by a comma.')}),) def _check_note(self, notes, lineno, line): + # First, simply check if the notes are in the line at all. This is an + # optimisation to prevent using the regular expression on every line, + # but rather only on lines which may actually contain one of the notes. + # This prevents a pathological problem with lines that are hundreds + # of thousands of characters long. + for note in self.config.notes: + if note in line: + break + else: + return + match = notes.search(line) if not match: return -- cgit v1.2.1