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 cyclic import with TYPE_CHECKING #4703

Merged
merged 5 commits into from Jul 19, 2021

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Jul 11, 2021

Description

Imports guarded by typing.TYPE_CHECKING should be added to the excluded_edges map so that they don't result in cyclic-import errors.

Type of Changes

Type
βœ“ πŸ› Bug fix

Related Issue

Closes #3525

@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
@cdce8p
Copy link
Member Author

cdce8p commented Jul 11, 2021

@Pierre-Sassoulas The change itself works. I just haven't gotten around to fully implement the tests, yet. Did I miss an easier way to test a whole package? (The result should be a clean run.) If you like, feel free to add the testing framework yourself as you probably know that part a bit better than I do.

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.

Maybe we can try to get inspiration from the old functional tests (test_func.py), so packages work in the new functional tests too. (It would also permit to finish the functional test migrations).

pylint/checkers/imports.py Show resolved Hide resolved
@@ -0,0 +1,7 @@
# pylint: disable=missing-docstring
Copy link
Member

Choose a reason for hiding this comment

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

Packages in functional tests are supposed to work (Matus Valo did a MR where it worked recently.) There's also a legacy functional test in test_func for cyclic import. (I thought the new functional test did not permit it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe you meant the tests here: #4678. After taking a closer look, they still only test a single module, no package.
It does however work with the old test_func framework.

Copy link
Member

Choose a reason for hiding this comment

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

Ha.. too bad. Adding the package check to the new functional tests would be great but I don't know how long it would take.

@cdce8p cdce8p added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jul 13, 2021
@cdce8p cdce8p marked this pull request as ready for review July 13, 2021 20:12
@cdce8p cdce8p modified the milestones: 2.9.4, 2.10.0 Jul 13, 2021
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.

Do you mind if we put this back in 2.9.4 as its a fix ?

@cdce8p cdce8p modified the milestones: 2.10.0, 2.9.4 Jul 13, 2021
@cdce8p
Copy link
Member Author

cdce8p commented Jul 13, 2021

Do you mind if we put this back in 2.9.4 as its a fix ?

Not at all. I think, It would make sense to move #4702 then, too. With the fix now merged..

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0006%) to 92.059% when pulling ec2004e on cdce8p:fix-cyclic-import into 3a6f08e on PyCQA:main.

@Pierre-Sassoulas Pierre-Sassoulas merged commit 6a16625 into pylint-dev:main Jul 19, 2021
@cdce8p cdce8p deleted the fix-cyclic-import branch July 19, 2021 19:57
rsarai added a commit to vintasoftware/aurorae that referenced this pull request Aug 16, 2021
…to prospector requirements: pylint-dev/pylint#4703. A fix for this will be discussed soon
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.

Imports within TYPE_CHECKING can induce "cyclic-import"
3 participants