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

Add ImportAlias node as children of Import nodes #912

Closed
wants to merge 14 commits into from

Conversation

msuozzo
Copy link

@msuozzo msuozzo commented Feb 26, 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

Since the name and alias metadata was already available as Import.names, the main addition here is of the location metadata associated with the alias. The intent is to generate line- and column-accurate lint locations in pylint for e.g. unused location.

For situations with compound imports (e.g. from foo import bar, baz, qux), addressing lints to a specific unused import instead of at the statement granularity as it is now would be a substantial quality-of-life improvement.

The ImportAlias node type shadows the _ast.alias type in the builtin ast module.

I've left the Import.names field to maintain backwards compatibility but it might be nice to change it to type list(ImportAlias) in the next major version.

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Related Issue

@msuozzo
Copy link
Author

msuozzo commented Mar 10, 2021

Any movement here? Should I link to the accompanying pylint change?

@hippo91
Copy link
Contributor

hippo91 commented Apr 8, 2021

@msuozzo thanks for this PR and sorry for the delay. I will try to have a look ASAP.

@hippo91 hippo91 self-assigned this Apr 8, 2021
Copy link
Contributor

@hippo91 hippo91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msuozzo thanks for this clear development!
Overall it looks good.
However i think adding tests would gives us more confidence.
Would you mind adding such a test in unittest_builder.py or unittest_raw_building.py?
By the way i would also have @cdce8p opinion on this.

@cdce8p
Copy link
Member

cdce8p commented Apr 9, 2021

I agree, this change should definitely have tests!
As for the code itself, the addition seems reasonable. I don't know what your opinion is @hippo91, but I would prefer to use type annotations for variables (instead of type comments) going forward. Additionally it might be a good idea to define / declare all possible instance variables inside __init__ and later reassign them, see pylint check for attribute-defined-outside-init.

@cdce8p
Copy link
Member

cdce8p commented Apr 9, 2021

We will also need to check for unintended side effects with pylint before merging it.

@cdce8p cdce8p added the ast label Sep 29, 2021
@cdce8p cdce8p mentioned this pull request Nov 14, 2022
10 tasks
@Pierre-Sassoulas Pierre-Sassoulas added Needs take over 🛎️ Orignal implementer went away but the code could be salvaged. and removed Waiting on author labels Nov 19, 2022
@Pierre-Sassoulas
Copy link
Member

@msuozzo are you still interested in finishing this PR ?

@DanielNoord
Copy link
Collaborator

Closing this as there no longer seems interest to finish this PR or add tests.

@DanielNoord DanielNoord closed this Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast Needs take over 🛎️ Orignal implementer went away but the code could be salvaged. python 3.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants