Skip to main content

flake8-define-class-attributes

PyPI - Python Version PyPI PyPI - License pre-commit.ci status

Check that class attributes are defined at the "top level" of your class. This is in the same spirit as Pylint's W0201 (attribute-defined-outside-init) error, expanded to allow attribute declaration at the class level.

For example:

Failing Code:

class Spaceship:
    def reset_location(self) -> None:
        self.xy = (0, 0)  # CLA001

Passing Code:

class Spaceship:
    def __init__(self):
        self.xy = (0, 0)

    def reset_location(self):
        self.xy = (0, 0)

# --OR--

class Spaceship:
    xy: tuple[int, int]

    def reset_location(self):
        self.xy = (0, 0)

When using dataclasses, __post_init__ methods are also considered when checking that an attribute has been defined.

Installation

Install from PyPi with your favorite pip invocation:

$ pip install flake8-define-class-attributes

It will then be run automatically as part of flake8.

You can verify it's being picked up by invoking the following in your shell:

$ flake8 --version
7.3.0 (flake8-define-class-attributes: 0.2.2, mccabe: 0.7.0, pycodestyle: 2.14.0, pyflakes: 3.4.0) CPython 3.13.5 on Darwin

Warnings

ID Description
CLA001 Attribute <name> not defined prior to assignment

Python Version Support

Beginning with Python 3.11, a best attempt is made to support Python versions until they reach EOL, after which support will be formally dropped by the next minor or major release of this package, whichever arrives first. The status of Python versions can be found here.

Metadata

Release files for flake8-define-class-attributes 0.2.2

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-define-class-attributes 0.2.2
File Size Uploaded
flake8_define_class_attributes-0.2.2.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-define-class-attributes 0.2.2
File Interpreter ABI Platform
flake8_define_class_attributes-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.1 kB

Release files / flake8_define_class_attributes-0.2.2.tar.gz

Download URL flake8_define_class_attributes-0.2.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
688d65c7fd41ae24804c0c1932e982117fef5c7554d2198821a92854c669a585
BLAKE2b-256 checksum
How to use checksums
6527e35b2257f6ead574d21b8832b1c2a8c1e6bb221652705bd9754f3b7cf52a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.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.

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 28, 2025.

Transparency log

Release files / flake8_define_class_attributes-0.2.2-py3-none-any.whl

Download URL flake8_define_class_attributes-0.2.2-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1a6350467e04ae75a17bee268224c94cbb06da706f9c8c442ee039d9609f7b8
BLAKE2b-256 checksum
How to use checksums
12b2805880f66deddb3cda86370c6dd23a67288e641e282c0cc18ad9db364d4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.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.

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 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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