Skip to main content

flake8-typing-as-t

Table of Contents

Overview

This is a flake8 plugin which ensures that imports from the typing library must be written using import typing as t.

Installation

pip install flake8-typing-as-t

Checks

  • TYT01: Bare import typing usage
  • TYT02: import typing as X where X is not literal t
  • TYT03: from typing import X usage
  • TYT80: Import of a name from typing which was deprecated in Python 3.9 and replaced with a builtin type.
  • TYT81: Import of a name from typing which was deprecated in Python 3.9 and has a planned removal.

Handling typing-extensions

A common pattern for compatibility is to do a sys.version_info-guarded dispatch over typing_extensions. e.g.

if sys.version_info < (3, 8):
    from typing_extensions import Literal
else:
    from typing import Literal

flake8-typing-as-t allows for this usage by checking if the import is inside of a test on sys.version_info against a tuple.

Configuring the Import Name

By default, flake8-typing-as-t enforces that the style be import typing as t. However, another common style, with the same benefits, is import typing as _t.

import typing as _t can be helpful in projects with strong policies around private vs public module members (including imported names).

To support this style, and other potential conventions, flake8-typing-as-t supports a config and CLI flag:

flake8 --typing-as-t-import-name "_t"

or, in .flake8 config:

[flake8]
typing-as-t-import-name = _t

Deprecated Name Rules

The TYT80 and TYT81 rules are slightly different in scope from the import rules. They check for attribute usage which accesses deprecated names like typing.Text or typing.Dict.

There are a large number of names in typing which are deprecated that are intentionally not flagged by these rules. The rationale for these omissions is that many of these renames and moves would inflict significant churn on codebases running flake8-typing-as-t.

Is it significantly better to use collections.abc.Iterator rather than typing.Iterator? The benefit is unclear. However! It is definitely better to use dict[A, B] over typing.Dict[A, B].

Inspiration and Rationale

I first saw import typing as t in the pallets projects, probably in flask or click.

It didn't click for me right away! But after working on various codebases with different strategies (including no strategy) for how to handling typing imports, the benefits became clear.

There are three primary consistent ways of handling typing imports:

  • always from typing import <Symbol>
  • always import typing
  • always import typing as t

Examining the problems with the other styles shows that import typing as t is the best choice.

The trouble with standardizing around the from-import style is that your import lines are constantly changing as code evolves.

+from typing import Any, ClassVar
-from typing import Any

Which means that as a reviewer, you are exposed to a lot more churn, and (much worse!) you frequently deal with "dumb" merge conflicts when two PRs change the same import lines.

import typing solves the conflict/diff problem, but frequently makes otherwise short function signature lines and other usages wrap.

Consider:

def foo(xs: typing.Iterator[T | None], ys: typing.Iterator[T | None]) -> typing.Iterator[tuple[T, T]]:
    for item1, item2 in zip(xs, ys):
        if item1 is not None and item2 is not None:
            yield (item1, item2)

vs

def foo(xs: t.Iterator[T | None], ys: t.Iterator[T | None]) -> t.Iterator[tuple[T, T]]:
    ...

That's a 102 character signature vs an 87 character one. A max line length of 88 chars is common. Surprisingly often, the extra characters in typing are the only reason that a line will wrap under code style rules.

A Neighbor of Builtins

Treating the typing module specially in your code, enforcing that it's always imported under a special single character name, also has a strong influence on how you think about typing in Python.

t becomes a special symbol for "parts of the type system". typing becomes more similar to the language level builtins, without the namespace pollution and readability problems we'd have with a star-import.

License

flake8-typing-as-t is distributed under the terms of the MIT license.

Changelog

1.2.0

  • flake8-typing-as-t now reports the TYT80 and TYT81 rules for catching fully deprecated usages.

1.1.0

  • Added support for configuring the import name, for as _t style

1.0.0

  • Initial production release

0.0.3

  • Internal refactoring for improved performance

0.0.2

  • Add support for sys.version_info dispatch

0.0.1

  • Initial release

Metadata

Release files for flake8-typing-as-t 1.2.0

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-typing-as-t 1.2.0
File Size Uploaded Provenance Actions
flake8_typing_as_t-1.2.0.tar.gz 6.0 kB With provenance Details for flake8_typing_as_t-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake8-typing-as-t 1.2.0
File Interpreter ABI Platform Actions
flake8_typing_as_t-1.2.0-py3-none-any.whl Python 3 none any Details for flake8_typing_as_t-1.2.0-py3-none-any.whl

Total release size: 12.2 kB

Release files / flake8_typing_as_t-1.2.0.tar.gz

Download URL flake8_typing_as_t-1.2.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
069e84fecdef42490d2497196eeac29f77314e4666e664b3b559e311d8a383ab
BLAKE2b-256 checksum
How to use checksums
9b39695f2eeb4f4b505168209c3ae53cd3df1e729a0a3216b82c2771ac3b8c2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / flake8_typing_as_t-1.2.0-py3-none-any.whl

Download URL flake8_typing_as_t-1.2.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d257b950e36e9c63fe3524b3211a36dc16eeb4a32dffe387862f5d827d1e2eae
BLAKE2b-256 checksum
How to use checksums
f883af3b219748e4ab60ab360e81e1688966ba97e9dc3eb1a0faa4e274324239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Security for flake8-typing-as-t 1.2.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flake8_typing_as_t-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

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