# flake8-classmethod-staticmethod
[![Build Status](https://github.com/atollk/flake8-classmethod-staticmethod/workflows/tox/badge.svg)](https://github.com/atollk/flake8-classmethod-staticmethod/actions)
[![Build Status](https://github.com/atollk/flake8-classmethod-staticmethod/workflows/black/badge.svg)](https://github.com/atollk/flake8-classmethod-staticmethod/actions)
flake8 plugin that checks rules regarding the staticmethod and classmethod decorators.
## Options
The plugin offers one flag, `--select_csm1`, accepting a list of error
codes (see below) to be enabled. By default, the enabled errors
are `CSM101` and `CSM131`.
## Error Codes
### CSM100
`@staticmethod` should not be used.
### CSM101
A method marked as `@staticmethod` should not reference the class it
is defined in. Use `@classmethod` otherwise.
**Bad**
```python
class MyClass:
@staticmethod
def my_name():
return MyClass.__name__
```
**Good**
```python
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
```
### CSM102
Do not inherit and override a method marked as `@staticmethod`.
**Bad**
```python
class MyClass:
@staticmethod
def my_name():
return "MyClass"
class MyChild:
@staticmethod
def my_name():
return "MyChild"
```
**Good**
```python
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
```
### CSM130
`@classmethod` should not be used.
### CSM131
A method marked as `@classmethod` should access the parameter `cls`.
Use `@staticmethod` otherwise.
**Bad**
```python
class MyClass:
@classmethod
def my_name(cls):
return "MyClass"
```
**Good**
```python
class MyClass:
@staticmethod
def my_name():
return "MyClass"
```
### CSM132
A method marked as `@classmethod` should not reference the class it
is defined in. Use the `cls` parameter.
```python
class MyClass:
@classmethod
def my_name(cls):
return MyClass.__name__
```
**Good**
```python
class MyClass:
@classmethod
def my_name(cls):
return cls.__name__
```
Raw data
{
"_id": null,
"home_page": "https://github.com/atollk/flake8-classmethod-staticmethod",
"name": "flake8-classmethod-staticmethod",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "flake8,classmethod,staticmethod",
"author": "Andreas Tollk\u00f6tter",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/da/b0/0c1d0f9269c956ba89f9ef608647be4178a7e083a1459e3d1167b3b2334a/flake8-classmethod-staticmethod-2.0.tar.gz",
"platform": null,
"description": "# flake8-classmethod-staticmethod\n[![Build Status](https://github.com/atollk/flake8-classmethod-staticmethod/workflows/tox/badge.svg)](https://github.com/atollk/flake8-classmethod-staticmethod/actions)\n[![Build Status](https://github.com/atollk/flake8-classmethod-staticmethod/workflows/black/badge.svg)](https://github.com/atollk/flake8-classmethod-staticmethod/actions)\n\n\nflake8 plugin that checks rules regarding the staticmethod and classmethod decorators.\n\n## Options\n\nThe plugin offers one flag, `--select_csm1`, accepting a list of error\ncodes (see below) to be enabled. By default, the enabled errors\nare `CSM101` and `CSM131`.\n\n## Error Codes\n\n### CSM100\n\n`@staticmethod` should not be used.\n\n### CSM101\n\nA method marked as `@staticmethod` should not reference the class it\nis defined in. Use `@classmethod` otherwise.\n\n**Bad** \n```python\nclass MyClass:\n @staticmethod\n def my_name():\n return MyClass.__name__\n```\n\n**Good** \n```python\nclass MyClass:\n @classmethod\n def my_name(cls):\n return cls.__name__\n```\n\n### CSM102\n\nDo not inherit and override a method marked as `@staticmethod`.\n\n**Bad** \n```python\nclass MyClass:\n @staticmethod\n def my_name():\n return \"MyClass\"\n\nclass MyChild:\n @staticmethod\n def my_name():\n return \"MyChild\"\n```\n\n**Good** \n```python\nclass MyClass:\n @classmethod\n def my_name(cls):\n return cls.__name__\n```\n\n### CSM130\n\n`@classmethod` should not be used.\n\n### CSM131\n\nA method marked as `@classmethod` should access the parameter `cls`.\nUse `@staticmethod` otherwise.\n\n**Bad** \n```python\nclass MyClass:\n @classmethod\n def my_name(cls):\n return \"MyClass\"\n```\n\n**Good** \n```python\nclass MyClass:\n @staticmethod\n def my_name():\n return \"MyClass\"\n```\n\n### CSM132\nA method marked as `@classmethod` should not reference the class it\nis defined in. Use the `cls` parameter.\n\n```python\nclass MyClass:\n @classmethod\n def my_name(cls):\n return MyClass.__name__\n```\n\n**Good** \n```python\nclass MyClass:\n @classmethod\n def my_name(cls):\n return cls.__name__\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "flake8 plugin that checks rules regarding the staticmethod and classmethod decorators.",
"version": "2.0",
"project_urls": {
"Homepage": "https://github.com/atollk/flake8-classmethod-staticmethod"
},
"split_keywords": [
"flake8",
"classmethod",
"staticmethod"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4669960b9954d0326085b9756a481de3b401f9d8a288835c02e0df2c00bb6bfe",
"md5": "55a0be220604d304ca3b94e7890c2fb3",
"sha256": "efafb2402f607790e160f890026f1a00a189dad5b8483966d65a237e9b6d8b89"
},
"downloads": -1,
"filename": "flake8_classmethod_staticmethod-2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "55a0be220604d304ca3b94e7890c2fb3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4673,
"upload_time": "2023-07-14T23:32:21",
"upload_time_iso_8601": "2023-07-14T23:32:21.738020Z",
"url": "https://files.pythonhosted.org/packages/46/69/960b9954d0326085b9756a481de3b401f9d8a288835c02e0df2c00bb6bfe/flake8_classmethod_staticmethod-2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dab00c1d0f9269c956ba89f9ef608647be4178a7e083a1459e3d1167b3b2334a",
"md5": "10458415d2f8abd13057993d2b46304e",
"sha256": "8efad452efd2b60a6bbe55c67d19179a0068dedb95bd896b1b044e3dd906bd68"
},
"downloads": -1,
"filename": "flake8-classmethod-staticmethod-2.0.tar.gz",
"has_sig": false,
"md5_digest": "10458415d2f8abd13057993d2b46304e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 3762,
"upload_time": "2023-07-14T23:32:23",
"upload_time_iso_8601": "2023-07-14T23:32:23.978904Z",
"url": "https://files.pythonhosted.org/packages/da/b0/0c1d0f9269c956ba89f9ef608647be4178a7e083a1459e3d1167b3b2334a/flake8-classmethod-staticmethod-2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-14 23:32:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "atollk",
"github_project": "flake8-classmethod-staticmethod",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "flake8-classmethod-staticmethod"
}