Check that class attributes are defined at the top level
Project description
flake8-define-class-attributes
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flake8_define_class_attributes-0.2.2.tar.gz.
File metadata
- Download URL: flake8_define_class_attributes-0.2.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
688d65c7fd41ae24804c0c1932e982117fef5c7554d2198821a92854c669a585
|
|
| MD5 |
75aa7d8c72a1881a01263eb664f7d983
|
|
| BLAKE2b-256 |
6527e35b2257f6ead574d21b8832b1c2a8c1e6bb221652705bd9754f3b7cf52a
|
Provenance
The following attestation bundles were made for flake8_define_class_attributes-0.2.2.tar.gz:
Publisher:
pypi_release.yml on sco1/flake8-define-class-attributes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flake8_define_class_attributes-0.2.2.tar.gz -
Subject digest:
688d65c7fd41ae24804c0c1932e982117fef5c7554d2198821a92854c669a585 - Sigstore transparency entry: 649740182
- Sigstore integration time:
-
Permalink:
sco1/flake8-define-class-attributes@30cd9fcbd3e62c78b256d554dfebc025a972c0f3 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/sco1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@30cd9fcbd3e62c78b256d554dfebc025a972c0f3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file flake8_define_class_attributes-0.2.2-py3-none-any.whl.
File metadata
- Download URL: flake8_define_class_attributes-0.2.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1a6350467e04ae75a17bee268224c94cbb06da706f9c8c442ee039d9609f7b8
|
|
| MD5 |
c37d6f4209155e33d18921c38a10a511
|
|
| BLAKE2b-256 |
12b2805880f66deddb3cda86370c6dd23a67288e641e282c0cc18ad9db364d4a
|
Provenance
The following attestation bundles were made for flake8_define_class_attributes-0.2.2-py3-none-any.whl:
Publisher:
pypi_release.yml on sco1/flake8-define-class-attributes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
flake8_define_class_attributes-0.2.2-py3-none-any.whl -
Subject digest:
f1a6350467e04ae75a17bee268224c94cbb06da706f9c8c442ee039d9609f7b8 - Sigstore transparency entry: 649740201
- Sigstore integration time:
-
Permalink:
sco1/flake8-define-class-attributes@30cd9fcbd3e62c78b256d554dfebc025a972c0f3 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/sco1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@30cd9fcbd3e62c78b256d554dfebc025a972c0f3 -
Trigger Event:
release
-
Statement type: