Skip to main content

flake8-pep585

This plugin enforces the changes proposed by PEP 585.

What does PEP 585 change?

Before PEP 585, you had to import stuff from typing to annotate some objects from the standard library:

  • For context managers, you'd import typing.ContextManager
  • For lists, you'd import typing.List
  • For callables, you'd import typing.Callable
  • ...and so on

With PEP 585, you can now use classes already present in the standard library. For example:

  • For a context manager giving an int, use contextlib.AbstractContextManager[int]
  • For a list of dicts mapping strs to ints, use list[dict[str, int]]
  • For a callable taking a float and returning an int, use collections.abc.Callable[[float], int]

typing.List, typing.Callable etc. are now deprecated. This is pretty hard to discover, since these imports don't cause a deprecation warning. IDEs don't help either: the "auto-import" feature often suggests importing a deprecated item.

This plugin lets you find these deprecated imports.

Examples

Direct import

from typing import Callable
PEA001 typing.Callable is deprecated, use collections.abc.Callable instead. See PEP 585 for details

Qualified import

from datetime import time
import typing as ty

def construct_time(match: ty.Match) -> time:
    return time(
        hour=int(match["hour"]),
        minute=int(match["minute"]),
    )
PEA001 typing.Match is deprecated, use re.Match instead. See PEP 585 for details

Installation

  1. Make sure you have flake8 installed
  2. Run pip install flake8-pep585
  3. Run flake8 on your code

Configuration

Via your setup.cfg file:

[flake8]
pep585-activation = always  # "always", "auto" or "never"

# Symbols that you're okay with being imported from `typing`
pep585-whitelisted-symbols =
    Callable
    Match
    Pattern

Via the CLI:

python -m flake8 --pep585-activation=always your_project/file.py

This only changes how the plugin behaves on Python 3.7.x and Python 3.8.x. By default ("auto"), it will be enabled if a from __future__ import annotations line is found.

Metadata

Release files for flake8-pep585 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-pep585 0.1.7
File Size Uploaded Provenance Actions
flake8-pep585-0.1.7.tar.gz 9.7 kB Without provenance Details for flake8-pep585-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake8-pep585 0.1.7
File Interpreter ABI Platform Actions
flake8_pep585-0.1.7-py3-none-any.whl Python 3 none any Details for flake8_pep585-0.1.7-py3-none-any.whl

Total release size: 20.5 kB

Release files / flake8-pep585-0.1.7.tar.gz

Download URL flake8-pep585-0.1.7.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
363f9413aa12849ee9bfdc437c4e79cc4e0fb3af4abbb61cfed79860e349e0e0
BLAKE2b-256 checksum
How to use checksums
e5d495ea172225cfacf81a329e3c8af7f91807409cf70fadf32f09992d779a1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.7.12 Linux/5.10.161-1-MANJARO

Release files / flake8_pep585-0.1.7-py3-none-any.whl

Download URL flake8_pep585-0.1.7-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5c7a5858382d6ca8c56554bd8bed090e12c378b98f6d7c6502abed9a40a658e
BLAKE2b-256 checksum
How to use checksums
d3b6ca9fb285698996160ff778db1115bebb4b46d4722d883a664646f027566b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.7.12 Linux/5.10.161-1-MANJARO

Security for flake8-pep585 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page