Lightning-AI / Lightning-AI/pytorch-lightning
Adopt PEP 563, PEP 585, and PEP 604
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
## Proposed refactor
We've dropped support for Python 3.6, which means we can use the new annotations format.
### Motivation
New shiny things are nice
### Pitch
Adopt [PEP 585](https://www.python.org/dev/peps/pep-0585/), [PEP 604](https://www.python.org/dev/peps/pep-0604/), and [PEP 563](https://www.python.org/dev/peps/pep-0563/).
We can do this automatically with the following sequence of commands:
```bash
# adds the future import to all files
isort -a "from __future__ import annotations" --append-only pytorch_lightning
# lets pyupgrade do its thing and use the new notation
pre-commit run pyupgrade --all-files
# remove the unused `from typing import ...` imports
autoflake -ir --remove-unused-variables pytorch_lightning
# format everything
pre-commit run black --all-files
```
Although some manual cleanup will be necessary because isort will add the import to all files, even those who don't need the `__future__` import
### Additional context
In regards to non-quoted annotations, there are talks of replacing [PEP 563](https://www.python.org/dev/peps/pep-0563/) with [PEP 649](https://www.python.org/dev/peps/pep-0649/). I don't think it impacts our project, but depending on the resolution of the latter the import statement might change.
Also, we might want to delay this until 1.6 will be released, to avoid conflicts with the bug-fix branch.
______________________________________________________________________
#### If you enjoy Lightning, check out our other projects! ⚡
- [**Metrics**](https://github.com/PyTorchLightning/metrics): Machine learning metrics for distributed, scalable PyTorch applications.
- [**Lite**](https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_lite.html): enables pure PyTorch users to scale their existing code on any kind of device while retaining full control over their own loops and optimization logic.
- [**Flash**](https://github.com/PyTorchLightning/lightning-flash): The fastest way to get a Lightning baseline! A collection of tasks for fast prototyping, baselining, fine-tuning, and solving problems with deep learning.
- [**Bolts**](https://github.com/PyTorchLightning/lightning-bolts): Pretrained SOTA Deep Learning models, callbacks, and more for research and production with PyTorch Lightning and PyTorch.
- [**Lightning Transformers**](https://github.com/PyTorchLightning/lightning-transformers): Flexible interface for high-performance research using SOTA Transformers leveraging Pytorch Lightning, Transformers, and Hydra.
cc @justusschock @awaelchli @akihironitta
Contributor guide
Research direction
Start in the pytorch_lightning directory and review the proposed isort, pyupgrade, autoflake, and black commands. Check the resulting annotation and import changes for files that do not need the future import, then run the formatting and cleanup checks. Done means the project adopts the PEP 563, PEP 585, and PEP 604 notation consistently without unnecessary imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100