Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix six with metaclass #893

Merged
merged 2 commits into from
Feb 12, 2021

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

tests/unittest_brain.py Show resolved Hide resolved
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants