diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2020-04-28 08:12:14 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2020-04-28 08:48:43 +0200 |
commit | 966e051d9770c9fff418f44be38ed85ca6a6ea1e (patch) | |
tree | a4177248fa21b11351276717f29fbfa9b2dbbfd8 | |
parent | 303b8d852e469379cd0f1a8891a018de5e39a966 (diff) | |
download | pylint-git-966e051d9770c9fff418f44be38ed85ca6a6ea1e.tar.gz |
Fix a crash in `method-hidden` lookup for unknown base classes
The patch replaces `mro()` with `ancestors()` as the former is not
fully capable of generating the complete linearization when
dealing with ambiguous inferences.
Close #3527
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | pylint/checkers/classes.py | 13 | ||||
-rw-r--r-- | tests/functional/m/method_hidden.py | 11 |
3 files changed, 24 insertions, 9 deletions
@@ -2,6 +2,15 @@ Pylint's ChangeLog ------------------ +What's New in Pylint 2.5.1? +=========================== + +Release date: TBA + +* Fix a crash in `method-hidden` lookup for unknown base classes + + Close #3527 + What's New in Pylint 2.5.0? =========================== diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index d96d6b9ed..775f8aad2 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -988,15 +988,10 @@ a metaclass class method.", return # If a subclass defined the method then it's not our fault. - try: - mro = klass.mro() - except (InconsistentMroError, DuplicateBasesError): - pass - else: - for subklass in mro[1 : mro.index(overridden_frame) + 1]: - for obj in subklass.lookup(node.name)[1]: - if isinstance(obj, astroid.FunctionDef): - return + for ancestor in klass.ancestors(): + for obj in ancestor.lookup(node.name)[1]: + if isinstance(obj, astroid.FunctionDef): + return args = (overridden.root().name, overridden.fromlineno) self.add_message("method-hidden", args=args, node=node) except astroid.NotFoundError: diff --git a/tests/functional/m/method_hidden.py b/tests/functional/m/method_hidden.py index 3070c3b5a..7131ba21a 100644 --- a/tests/functional/m/method_hidden.py +++ b/tests/functional/m/method_hidden.py @@ -79,3 +79,14 @@ class One: class Two(One): def one(self): pass + +try: + import unknown as js +except ImportError: + import json as js + + +class JsonEncoder(js.JSONEncoder): + # pylint: disable=useless-super-delegation + def default(self, o): + return super(JsonEncoder, self).default(o) |