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

add python type hints via pyre infer to tests/ #11953

Closed
wants to merge 2 commits into from

Conversation

edward-io
Copy link
Contributor

@edward-io edward-io commented Feb 17, 2022

What does this PR do?

automatically adds python type hinting using pyre to tests.

manually fixed some broken areas.

breaking this up into multiple PRs to make it easier to review.

Does your PR introduce any breaking changes? If yes, please list them.

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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 🙃

@mergify mergify bot removed the has conflicts label Feb 17, 2022
@edward-io edward-io changed the title add python type hints via pyre infer add python type hints via pyre infer to tests/ Feb 17, 2022
@edward-io edward-io force-pushed the pyre-typing branch 5 times, most recently from e490ee7 to a27eb66 Compare February 17, 2022 09:58
@carmocca
Copy link
Contributor

We aren't interested in adding typing to tests. The type checker is not configured to run over them.

Tests will naturally fail if types are not correct. Typing is most useful for users but tests are internal to the project.

@Borda
Copy link
Member

Borda commented Feb 17, 2022

@edward-io do you think this could be used for the package instead to fill some of the missing typing? 🐰

@edward-io
Copy link
Contributor Author

edward-io commented Feb 17, 2022

@carmocca Typing helps beyond correctness in tests - it helps with autocomplete in text editors and provides self-documentation for easier readability as well :) If we don't think that the benefits outweigh the costs, I can go ahead and close this PR.

@Borda - #11956 #11955, I'll add another one for the main library as well.

@carmocca
Copy link
Contributor

carmocca commented Feb 17, 2022

@edward-io Sorry if I sounded too harsh with my previous comment! Let me elaborate.

Mypy is not configured to run over the test directory:

https://github.com/PyTorchLightning/pytorch-lightning/blob/25b505508d376d87103a592f23f7c9b0a602d12e/pyproject.toml#L26

So I would not be comfortable adding type information if it's not going to be checked. The cost of running the bot is negligible, however, adding types without the checker is like adding code without tests.

Considering that there is still a lot of the source code still untyped, I would focus on that. Maybe one day it's worth adding type annotations for tests but it's very low value and the test suite is already very fragmented.

I'll add another one for the main library as well.

For other typing PRs to the codebase, you should aim to remove entries from:

https://github.com/PyTorchLightning/pytorch-lightning/blob/25b505508d376d87103a592f23f7c9b0a602d12e/pyproject.toml#L45-L98

but keep in mind that each PR should address only one or a few files. You can see examples in the linked PRs to #7037

@edward-io edward-io closed this Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants