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

Ignore import errors if in guarded import block #4702

Merged
merged 3 commits into from Jul 19, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Jul 11, 2021

Description

Ignore the following error messages if import is in guarded if block (sys.version_info or typing.TYPE_CHECKING):

  • import-error
  • no-name-in-module
  • ungrouped-imports

Although just ignoring them isn't ideal, that seems to be the best we can do here. Besides, a fix seems to be highly requested.

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #3285
Closes #3382

@cdce8p cdce8p added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 11, 2021
@cdce8p cdce8p added this to the 2.9.4 milestone Jul 11, 2021
@coveralls
Copy link

coveralls commented Jul 11, 2021

Coverage Status

Coverage increased (+0.001%) to 92.059% when pulling 6653bc8 on cdce8p:guarded-import-block into 6950464 on PyCQA:main.

@cdce8p
Copy link
Member Author

cdce8p commented Jul 11, 2021

@Pierre-Sassoulas What do you think? I'm open to other ideas if you have any

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.

Good job on adding the typing, little by little we'll end up having proper typing :D

pylint/checkers/utils.py Show resolved Hide resolved
@cdce8p cdce8p added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jul 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.9.4, 2.10.0 Jul 13, 2021
@cdce8p cdce8p modified the milestones: 2.10.0, 2.9.4 Jul 14, 2021
@cdce8p cdce8p force-pushed the guarded-import-block branch 2 times, most recently from 9016282 to 77ba57b Compare July 14, 2021 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pylint reports ungrouped-imports for TYPE_CHECKING imports Add option to ignore code in if TYPE_CHECKING
3 participants