Skip to content

Add sys.version_info guard to import-error #4468

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

Merged
merged 1 commit into from
May 11, 2021
Merged

Add sys.version_info guard to import-error #4468

merged 1 commit into from
May 11, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented May 11, 2021

Description

Suggested by @KapJI here: home-assistant/core#50444 (comment)

Don't emit an import-error if import is guarded behind if sys.version_info. Since pylint can only check the python version it's executed with, this often results in a false-positive.

The current suggestion doesn't account for imports that are truly missing, since the if statement can't (yet) be easily inferred. Implementing this would be possible, but probably not worth it.

Examples

import sys

if sys.version_info >= (3, 9):
    import zoneinfo

if sys.version_info[:2] >= (3, 9):
    import zoneinfo

If tested with pylint <= 3.8, this would have resulted in an import-error without this change.

Type of Changes

Type
✨ New feature

@cdce8p cdce8p requested a review from Pierre-Sassoulas May 11, 2021 21:33
@cdce8p cdce8p added the False Positive 🦟 A message is emitted but nothing is wrong with the code label May 11, 2021
@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 91.728% when pulling 979421e on cdce8p:improve-import-error into 6044930 on PyCQA:master.

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.

Make sense!

@cdce8p cdce8p merged commit 9b268ec into pylint-dev:master May 11, 2021
@cdce8p cdce8p deleted the improve-import-error branch May 13, 2021 20:32
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants