Add unconditional import when type checking#6500
Closed
kandluis wants to merge 3 commits intoLightning-AI:masterfrom
Closed
Add unconditional import when type checking#6500kandluis wants to merge 3 commits intoLightning-AI:masterfrom
kandluis wants to merge 3 commits intoLightning-AI:masterfrom
Conversation
Borda
reviewed
Mar 12, 2021
|
Hello @kandluis! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-03-18 16:28:08 UTC |
45c4292 to
3fc14f3
Compare
Borda
reviewed
Mar 16, 2021
3fc14f3 to
2f6ce1a
Compare
Contributor
Author
|
Accidentally closed. Reopening. Refactored to keep only imports in the if/else branches. |
f7418f2 to
a862e32
Compare
SeanNaren
approved these changes
Mar 18, 2021
Contributor
SeanNaren
left a comment
There was a problem hiding this comment.
I'll approve however not too well versed here, pinging @carmocca @kaushikb11 who may have more input.
Contributor
|
@Borda Any updates ? |
Collaborator
Contributor
Author
|
Thanks @Borda for merging into refactors! :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Without this change, when type checking using
pyre(and possibly as well usingmypythough I've not verified this) imports such as:raise errors due to the fact that they're only conditionally imported at the module level.
A workaround is to change imports to the following:
However, large chunks of our documentation do not reflect this pattern. As such, this small update to the logic in the
__init__.pyfunction makes it so that when type checking (typing.TYPE_CHECKING === True) the imports are unconditional, fixing any warnings from the checkers.This is okay since the only time the imports do not occur is when were' in the build-phase of the library.
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃