Skip to content

Commit

Permalink
Fix a crash in method-hidden lookup for unknown base classes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PCManticore committed Apr 28, 2020
1 parent 089f510 commit 100eb13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
===========================

Expand Down
13 changes: 4 additions & 9 deletions pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,15 +988,10 @@ def visit_functiondef(self, node):
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:
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/m/method_hidden.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ def one(self): # [method-hidden]
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)

0 comments on commit 100eb13

Please sign in to comment.