Skip to content

Adopt PEP 563, PEP 585, and PEP 604 #11205

@carmocca

Description

@carmocca

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, PEP 604, and PEP 563.

We can do this automatically with the following sequence of commands:

# 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 with PEP 649. 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: Machine learning metrics for distributed, scalable PyTorch applications.

  • Lite: 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: 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: Pretrained SOTA Deep Learning models, callbacks, and more for research and production with PyTorch Lightning and PyTorch.

  • Lightning Transformers: Flexible interface for high-performance research using SOTA Transformers leveraging Pytorch Lightning, Transformers, and Hydra.

cc @justusschock @awaelchli @akihironitta

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions