flake8 plugin that checks rules regarding the staticmethod and classmethod decorators.
Project description
flake8-classmethod-staticmethod
flake8 plugin that checks rules regarding the staticmethod and classmethod decorators.
Options
The plugin offers one flag, --select_clst1
, accepting a list of error
codes (see below) to be enabled. By default, the enabled errors
are CLST101
and CLST131
.
Error Codes
CLST100
@staticmethod
should not be used.
CLST101
A method marked as @staticmethod
should not reference the class it
is defined in. Use @classmethod
otherwise.
Bad
class MyClass:
@staticmethod
def my_name():
return MyClass.__name__
Good
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
CLST102
Do not inherit and override a method marked as @staticmethod
.
Bad
class MyClass:
@staticmethod
def my_name():
return "MyClass"
class MyChild:
@staticmethod
def my_name():
return "MyChild"
Good
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
CLST130
@classmethod
should not be used.
CLST131
A method marked as @classmethod
should access the parameter cls
.
Use @staticmethod
otherwise.
Bad
class MyClass:
@classmethod
def my_name(cls):
return "MyClass"
Good
class MyClass:
@staticmethod
def my_name():
return "MyClass"
CLST132
A method marked as @classmethod
should not reference the class it
is defined in. Use the cls
parameter.
class MyClass:
@classmethod
def my_name(cls):
return MyClass.__name__
Good
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file flake8-classmethod-staticmethod-1.0.tar.gz
.
File metadata
- Download URL: flake8-classmethod-staticmethod-1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f8a11ff168f393a731d5c3e3f738a04b9fe2fe71e1a11fb30920da874816ba9 |
|
MD5 | 1f0e53011bf42effbd8e540883be77d0 |
|
BLAKE2b-256 | 06b62f584bd887088bff70ccde09600b1351565ecb18444c0af4d34b16020889 |
File details
Details for the file flake8_classmethod_staticmethod-1.0-py3-none-any.whl
.
File metadata
- Download URL: flake8_classmethod_staticmethod-1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16f9c960c261b06d9a243f54648c9a8121a9899f89b567fcb7be3e1dc414683b |
|
MD5 | 58b3af467723e6e39fd3a17dfaa8b586 |
|
BLAKE2b-256 | 61b103eb67755b805fd010030a6e02b2c481a1cf5bc9f3825bd6a4ec6291c0e0 |