skip to navigation
skip to content

flake8-pyi 17.3.0

A plugin for flake8 to enable linting .pyi files.

A plugin for Flake8 that provides specializations for type hinting stub files, especially interesting for linting typeshed.


  1. Adds the .pyi extension to the default value of the --filename command-line argument to Flake8. This means stubs are linted by default with this plugin enabled, without needing to explicitly list every file.
  2. Modifies PyFlakes runs for .pyi files to defer checking type annotation expressions after the entire file has been read. This enables support for first-class forward references that stub files use.

The latter should ideally be merged into flake8 as the integration is currently pretty brittle (might break with future versions of pyflakes, flake8, or due to interactions with other overly clever plugins).

List of warnings

This plugin reserves codes starting with Y0. The following warnings are currently emitted:

  • Y001: Names of TypeVars in stubs should start with _. This makes sure you don’t accidentally expose names internal to the stub.
  • Y002: If test must be a simple comparison against sys.platform or sys.version_info. Stub files support simple conditionals to indicate differences between Python versions or platforms, but type checkers only understand a limited subset of Python syntax, and this warning triggers on conditionals that type checkers will probably not understand.
  • Y003: Unrecognized sys.version_info check. Similar, but triggers on some comparisons involving version checks.
  • Y004: Version comparison must use only major and minor version. Type checkers like mypy don’t know about patch versions of Python (e.g. 3.4.3 versus 3.4.4), only major and minor versions (3.3 versus 3.4). Therefore, version checks in stubs should only use the major and minor versions. If new functionality was introduced in a patch version, pretend that it was there all along.
  • Y005: Version comparison must be against a length-n tuple.
  • Y006: Use only < and >= for version comparisons. Comparisons involving > and <= may produce unintuitive results when tools do use the full sys.version_info tuple.
  • Y007: Unrecognized sys.platform check. Platform checks should be simple string comparisons.
  • Y008: Unrecognized platform. To prevent you from typos, we warn if you use a platform name outside a small set of known platforms (e.g. “linux” and “win32”).
  • Y009: Empty body should contain “…”, not “pass”. This is just a stylistic choice, but it’s the one typeshed made.
  • Y010: Function body must contain only “…”. Stub files should not contain code, so function bodies should be empty. Currently, we make exceptions for raise statements and for assignments in __init__ methods.

The following warnings are disabled by default:

  • Y090: Use explicit attributes instead of assignments in __init__. This is a stricter version of Y010. Instead of:

    class Thing:
        def __init__(self, x: str) -> None:
            self.x = x

    you should write:

    class Thing:
        x: str
        def __init__(self, x: str) -> None: ...




Just run:

python3.6 test

Note: tests require 3.6+ due to testing variable annotations.

Change Log


  • introduce Y001 - Y010
  • introduce optional Y090


  • handle del statements in stub files


  • handle annotated assignments in 3.6+ with forward reference support


  • handle forward references during subclassing on module level
  • handle forward references during type aliasing assignments on module level


  • first published version
  • date-versioned


Glued together by Łukasz Langa and Jelle Zijlstra.

File Type Py Version Uploaded on Size
flake8-pyi-17.3.0.tar.gz (md5, pgp) Source 2017-03-27 9KB
flake8_pyi-17.3.0-py35.py36-none-any.whl (md5, pgp) Python Wheel py35.py36 2017-03-27 10KB