Skip to content

Conversation

@kandluis
Copy link
Contributor

@kandluis kandluis commented Mar 12, 2021

What does this PR do?

Without this change, when type checking using pyre (and possibly as well using mypy though I've not verified this) imports such as:

from pytorch_lightning import Trainer

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:

from pytorch_lightning.trainer import Trainer

However, large chunks of our documentation do not reflect this pattern. As such, this small update to the logic in the __init__.py function 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

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

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:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@Borda Borda added the feature Is an improvement or enhancement label Mar 12, 2021
Copy link
Contributor

@ananthsub ananthsub left a comment

Choose a reason for hiding this comment

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

thanks for the fix!

@pep8speaks
Copy link

pep8speaks commented Mar 16, 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

@kandluis kandluis force-pushed the types/unconditonal_imports branch from 45c4292 to 3fc14f3 Compare March 16, 2021 04:27
@kandluis kandluis closed this Mar 17, 2021
@kandluis kandluis force-pushed the types/unconditonal_imports branch from 3fc14f3 to 2f6ce1a Compare March 17, 2021 18:21
@kandluis
Copy link
Contributor Author

Accidentally closed. Reopening. Refactored to keep only imports in the if/else branches.

@kandluis kandluis reopened this Mar 17, 2021
@kandluis kandluis force-pushed the types/unconditonal_imports branch from f7418f2 to a862e32 Compare March 18, 2021 16:27
Copy link
Contributor

@SeanNaren SeanNaren left a comment

Choose a reason for hiding this comment

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

I'll approve however not too well versed here, pinging @carmocca @kaushikb11 who may have more input.

@Borda Borda mentioned this pull request Mar 19, 2021
11 tasks
@tchaton
Copy link
Contributor

tchaton commented Mar 22, 2021

@Borda Any updates ?

@Borda
Copy link
Collaborator

Borda commented Mar 22, 2021

@Borda Any updates ?

it is ready to land #6590 just need your confirmation...

@kandluis
Copy link
Contributor Author

Thanks @Borda for merging into refactors! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Is an improvement or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants