Skip to content

Conversation

@hippo91
Copy link
Contributor

@hippo91 hippo91 commented Feb 11, 2021

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

This PR corrects the brain dealing with six.with_metaclass.
The error came from the tweaking of the node bases. It has not to be done.
For example, following code:

from astroid import extract_node src = """ class A: pass def get_parent(): return A class B(get_parent()): pass B """ node=extract_node(src) cls_node = node.inferred()[0] print(list(cls_node.bases)) print(list(cls_node.ancestors())) 

gives:

[<Call l.8 at 0x7f0ad5ecc250>] [<ClassDef.A l.2 at 0x7f0ad5faf350>, <ClassDef.object l.0 at 0x7f0ad6ea45d0>] 

The base is a CallNode, whereas the ancestors are ClassDef from the class hierarchy.
Thus in the six.with_metaclass case, the base has to be a call node.
Doing this, the six module is seen as really used and this avoids the emission of unused-import message.

This PR should correct the failing CI on pylint side.

Type of Changes

Type
🐛 Bug fix

Related Issue

Failing CI on pylint.

…e unused-import due to the fact that six.with_metaclass is not consumed. Adds a unittest to check that bases attribute holds a call node and that ancestors attributes returns the correct class hierarchy.
@hippo91
Copy link
Contributor Author

hippo91 commented Feb 11, 2021

@fmigneault are you ok with this change?
Related discussion:
#890 #841 pylint-dev/pylint#4006

@Pierre-Sassoulas Pierre-Sassoulas merged commit 6189473 into pylint-dev:master Feb 12, 2021
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 15, 2022
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 15, 2022
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 15, 2022
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this pull request Jun 15, 2022
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 23, 2022
adam-grant-hendry pushed a commit to adam-grant-hendry/astroid that referenced this pull request Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants