flake8-classmethod-staticmethod


Nameflake8-classmethod-staticmethod JSON
Version 2.1 PyPI version JSON
download
home_pagehttps://github.com/atollk/flake8-classmethod-staticmethod
Summaryflake8 plugin that checks rules regarding the staticmethod and classmethod decorators.
upload_time2024-06-02 19:02:22
maintainerNone
docs_urlNone
authorAndreas Tollkötter
requires_python>=3.8
licenseMIT
keywords flake8 classmethod staticmethod
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.
A special case that is exempt is a method that has a call to `super()`.

**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": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "flake8, classmethod, staticmethod",
    "author": "Andreas Tollk\u00f6tter",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/cd/5e/35b53a5fb9e490260365b03443065b68221d5596970579807bf560e37bf2/flake8_classmethod_staticmethod-2.1.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.\nA special case that is exempt is a method that has a call to `super()`.\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.1",
    "project_urls": {
        "Homepage": "https://github.com/atollk/flake8-classmethod-staticmethod"
    },
    "split_keywords": [
        "flake8",
        " classmethod",
        " staticmethod"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2cefb7292f6a3146d86bd2be38ec35db5c53116f4511b4ed92d585c06ef46b97",
                "md5": "2edbc9a257f6f433a266bd1bbd40d726",
                "sha256": "44ca4822be9e403456d650c3edba0b2805dcd51f10dbe5bde05b8b104ffcd74f"
            },
            "downloads": -1,
            "filename": "flake8_classmethod_staticmethod-2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2edbc9a257f6f433a266bd1bbd40d726",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4789,
            "upload_time": "2024-06-02T19:02:20",
            "upload_time_iso_8601": "2024-06-02T19:02:20.765238Z",
            "url": "https://files.pythonhosted.org/packages/2c/ef/b7292f6a3146d86bd2be38ec35db5c53116f4511b4ed92d585c06ef46b97/flake8_classmethod_staticmethod-2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd5e35b53a5fb9e490260365b03443065b68221d5596970579807bf560e37bf2",
                "md5": "52be68f9623eb9e8bdd92928258b779d",
                "sha256": "26eba8e11e44f7f6a41cca49bf875e3e7d1ef8b06de84ebf496bb9b6845d3d52"
            },
            "downloads": -1,
            "filename": "flake8_classmethod_staticmethod-2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "52be68f9623eb9e8bdd92928258b779d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4624,
            "upload_time": "2024-06-02T19:02:22",
            "upload_time_iso_8601": "2024-06-02T19:02:22.232400Z",
            "url": "https://files.pythonhosted.org/packages/cd/5e/35b53a5fb9e490260365b03443065b68221d5596970579807bf560e37bf2/flake8_classmethod_staticmethod-2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-02 19:02:22",
    "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"
}
        
Elapsed time: 0.60155s