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

Clearer reimported and new shadowed-import messages for aliased import #7756

Merged
merged 7 commits into from
Nov 30, 2022

Conversation

clavedeluna
Copy link
Collaborator

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #4836

Issue brought up the fact that the reimported message was confusing and hinted at something else, while also giving us more test cases to improve the check for imports using aliases.

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative πŸ¦‹ No message is emitted but something is wrong with the code label Nov 12, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

LGTM, I would go further and rename reimported to something like import-name-clashor something clearer about what the problem is. "reimported" feel like what should be raised for:

from pathlib import Path
from pathlib import Path

Which is a lot less problematic than the problem we detect here.

Comment on lines 1 to 4
# pylint: disable=missing-docstring,unused-import,import-error, wildcard-import,unused-wildcard-import,redefined-builtin,no-name-in-module,ungrouped-imports,wrong-import-order,wrong-import-position,consider-using-from-import

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# pylint: disable=missing-docstring,unused-import,import-error, wildcard-import,unused-wildcard-import,redefined-builtin,no-name-in-module,ungrouped-imports,wrong-import-order,wrong-import-position,consider-using-from-import
# pylint: disable=missing-docstring,unused-import,import-error, wildcard-import,unused-wildcard-import,redefined-builtin,no-name-in-module
# pylint: disable=ungrouped-imports, wrong-import-order,wrong-import-position,consider-using-from-import

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3452479310

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.0008%) to 95.383%

Totals Coverage Status
Change from base Build 3452308194: 0.0008%
Covered Lines: 17292
Relevant Lines: 18129

πŸ’› - Coveralls

@Pierre-Sassoulas
Copy link
Member

I realize by reading the issue that we already had this discussion. Now that I think about it again this feel like a new check, which should have a different message and probably also a different level (warning at least, while reimported is probably just a convention).

@clavedeluna
Copy link
Collaborator Author

I followed the conclusion of the issue. If maintainers would like to change scope, lmk I will close this.

@Pierre-Sassoulas
Copy link
Member

Let's pursue the discussion in the original issue. I feel that your implementation would permit to separate the two use case relatively easily though.

@github-actions

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

Let's separate the two checks between reimported and shadowed-import. I also think that this is a false positive for shadowed-import as the import is not shadowed:

from pandas._libs import (
    algos as libalgos,
    hashtable as ht,
)
import pandas.core.algorithms as algos

But this should raise shadowed-import:

from pandas._libs import (
    algos,
    hashtable as ht,
)
import pandas.core.algorithms as algos  # [shadowed-import]

And this should raise reimported:

from pandas._libs import (
    algos as libalgos,
    hashtable as ht,
)
import pandas._libs.algos as algos  # [reimported]

@clavedeluna
Copy link
Collaborator Author

As a principle, I don't like changing the scope of a PR after work that could be merged is complete. This PR could be merged as is, and through an iterative process, a new issue can be opened to then separate the two checks. Without this, you're asking a contributor to do more work than they initially signed up for in an issue. So not saying scope can't change -it always will. Just saying that we should manage it by cutting it with issues.

@Pierre-Sassoulas
Copy link
Member

Sorry about that but I don't think this is mergeable as is. This would make reimported confusing by adding a new use case that does not correspond to the current name and we'd have to make real breaking change to correct it later if we release it. (a user disable reimported somewhere and the message then change to import-shadowed and she has to disable it again) So if we merge this it's going to make the main branch un-realeasable until someone fix it and that's not something I want to have to keep in mind.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Looks pretty great πŸ‘ Some minor nitpicks and let's merge !

doc/whatsnew/fragments/4836.bugfix Outdated Show resolved Hide resolved
pylint/checkers/imports.py Outdated Show resolved Hide resolved
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Nov 30, 2022
@github-actions
Copy link
Contributor

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit 4e58ebe

@Pierre-Sassoulas Pierre-Sassoulas merged commit 1ff7c7a into pylint-dev:main Nov 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title reimported should detect aliased imports Clearer reimported and new shadowed-import messages for aliased import Nov 30, 2022
@@ -0,0 +1,3 @@
Update ``reimported`` help message for clarity and add a ``shadowed-import`` message for aliased imports.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should burry the new message in the bugfix section. That's a case where to changelog entries would make sense. One bugfix and one new_check.

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative reimported when using an import alias
4 participants