Name | eo-styleguide JSON |
Version |
0.0.1a16
JSON |
| download |
home_page | None |
Summary | Pyeo is an advanced static analysis tool tailored specifically to enforce the principles advocated by Elegant Objects (elegantobjects.org) in Python projects. It serves as a quality control instrument to ensure that your Python code adheres to the core tenets of elegance, simplicity, and maintainability. |
upload_time | 2024-12-05 10:28:35 |
maintainer | None |
docs_url | None |
author | Almaz Ilaletdinov |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pyeo
[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)
Pyeo is an advanced static analysis tool tailored specifically to enforce the principles advocated by
Elegant Objects (elegantobjects.org) in Python projects. It serves as a quality control instrument to ensure
that your Python code adheres to the core tenets of elegance, simplicity, and maintainability.
Pyeo is proudly based on the robust foundation of [Mypy](https://github.com/python/mypy), a leading static type checker for Python. Mypy not only provides excellent type analysis capabilities but also offers a convenient-to-use API and abstractions for working with Python AST (Abstract Syntax Tree). This unique combination empowers Pyeo a seamless static analysis experience, allowing for a deeper understanding of your code's structure and semantics.
The project is inspired by the team that made fun of me because of the lego build. STT lambda ❤️️
```bash
pip install eo-styleguide
```
setup.cfg/mypy.ini
```
[mypy]
plugins = pyeo.main
```
pyproject.toml
```
[tool.mypy]
plugins = ["pyeo.main"]
```
Simple example of usage:
```python
from typing import Protocol, final
import attrs
# use the "elegant" decorator so that the plugin finds classes to check
from pyeo import elegant
class House(Protocol):
def area(self) -> int: ...
@elegant
@final
@attrs.define(frozen=True)
class HttpHouse(House):
def area(self) -> int:
return 10
```
## Contents
- Principles
- [No null](#no-null) ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html))
- [No code in constructors](#no-code-in-constructors) ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html))
- [No getters and setters](#no-getters-and-setters) ([why?](http://www.yegor256.com/2014/09/16/getters-and-setters-are-evil.html))
- [No mutable objects](#no-mutable-objects) ([why?](http://www.yegor256.com/2014/06/09/objects-should-be-immutable.html))
- [No readers, parsers, controllers, sorters, and so on](#no-er-suffix) ([why?](https://www.yegor256.com/2015/03/09/objects-end-with-er.html))
- [No static methods, not even private ones](no-static-methods) ([why?](http://www.yegor256.com/2017/02/07/private-method-is-new-class.html))
- [No instanceof, type casting, or reflection](no-reflection) ([why?](http://www.yegor256.com/2015/04/02/class-casting-is-anti-pattern.html))
- [No public methods without a contract (interface)](#no-public-methods-without-a-contract) ([why?](https://www.yegor256.com/2014/11/20/seven-virtues-of-good-object.html#2-he-works-by-contracts))
- [No statements in test methods except assert](#no-statements-in-tests) ([why?](http://www.yegor256.com/2017/05/17/single-statement-unit-tests.html))
- [No ORM or ActiveRecord](#no-orm) ([why?](https://www.yegor256.com/2014/12/01/orm-offensive-anti-pattern.html) and [why?](https://www.yegor256.com/2016/07/26/active-record.html))
- [No implementation inheritance](#no-inheritance) ([why?](http://www.yegor256.com/2017/01/31/decorating-envelopes.html) and [why?](http://www.yegor256.com/2016/09/13/inheritance-is-procedural.html))
## No null
Mypy helps prevent `AttributeError` and other type-related errors by providing static type checking for Python code. It allows specifying variable types, function arguments, and return types to catch potential type issues before the program runs. By using Mypy, developers can identify and fix problems related to attribute access and other type mismatches, leading to improved code quality and easier maintenance.
Example:
```python
class Employee(object):
def __init__(self, user_id: int):
self._user_id = user_id
def get_by_id(user_id: int) -> Employee:
if user_id < 0:
return None
return Employee(user_id)
```
Mypy return next violation:
```
error: Incompatible return value type (got "None", expected "Employee") [return-value]
```
So, we must use `typing.Optional` or `|` (union) operator.
It's works:
```
def get_by_id(user_id: int) -> Optional[Employee]: ...
def get_by_id(user_id: int) -> Employee | None: ...
```
## No code in constructors
You can use `@attrs.define` for skip this. It decorator create ctor for your classes automatically. However, we implement check that your primary and secondary ctors not contain code, with the exception of attributes assingment. Please check [NoCodeInCtorFeature](/pyeo/features/no_code_in_ctors.py).
## No getters and setters
Actually we realize functional for to prohibit the use of `@property` and `@setter` method decorators. You can use `@attrs.define(frozen=True)` in order to make an object immutable.
Prohibit the use of `@property` decorator not protect from evil of getters, so if you can ideas how we can implement more complex check, create issue please.
## No mutable objects
`attrs.define(frozen=True)` is a parameter used in the attrs library to create classes with attributes that cannot be modified after the instance is created (i.e., immutable or "frozen" classes).
The [attrs](https://www.attrs.org/en/stable/) library allows defining classes using the `@attr.s` decorator or by explicitly calling the `attr.define` function, and `frozen=True` is one of the parameters for specifying attribute behavior in the class.
When you use `attrs.define(frozen=True)` for a class, all its attributes become read-only after the instance is created, making the class "frozen" or "immutable," preventing any changes to its attribute values.
## No er suffix
We check you class name not contain `-er` or `(C|c)lient` suffix by check in [NoErNamesFeature](/pyeo/features/no_er_names.py)
## No static methods
Check by [NoStaticmethodsFeature](/pyeo/features/no_staticmethods.py)
## No reflection
Prohibit next function calls:
- `isinstance`
- `type`
- `issubclass`
- `hasattr`
## No public methods without a contract
In Python, `typing.Protocol` is a class introduced in Python 3.8 as part of the typing module. It is used to define structural subtyping or "duck typing" for classes, which allows you to create interfaces without using explicit inheritance.
[EachMethodHasProtocolFeature](/pyeo/features/method_has_protocol.py) rule check that all of public class methods has protocol.
## No statements in tests
TODO
## No ORM
Detect using ORM or ActiveRecord tools on project by design/code review
## No inheritance
Each `@elegant` object must be `typing.final`. Check by [FinalClassFeature](/pyeo/features/final_object.py)
Raw data
{
"_id": null,
"home_page": null,
"name": "eo-styleguide",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Almaz Ilaletdinov",
"author_email": "a.ilaletdinov@yandex.ru",
"download_url": "https://files.pythonhosted.org/packages/19/f5/ec9370830a96e59cdbde2f52ebb6984f8e6daedb742b066b56a399aeaff9/eo_styleguide-0.0.1a16.tar.gz",
"platform": null,
"description": "# pyeo\n\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n\nPyeo is an advanced static analysis tool tailored specifically to enforce the principles advocated by\nElegant Objects (elegantobjects.org) in Python projects. It serves as a quality control instrument to ensure\nthat your Python code adheres to the core tenets of elegance, simplicity, and maintainability.\n\nPyeo is proudly based on the robust foundation of [Mypy](https://github.com/python/mypy), a leading static type checker for Python. Mypy not only provides excellent type analysis capabilities but also offers a convenient-to-use API and abstractions for working with Python AST (Abstract Syntax Tree). This unique combination empowers Pyeo a seamless static analysis experience, allowing for a deeper understanding of your code's structure and semantics.\n\nThe project is inspired by the team that made fun of me because of the lego build. STT lambda \u2764\ufe0f\ufe0f\n\n\n```bash\npip install eo-styleguide\n```\n\nsetup.cfg/mypy.ini\n```\n[mypy]\nplugins = pyeo.main\n```\n\npyproject.toml\n```\n[tool.mypy]\nplugins = [\"pyeo.main\"]\n```\n\nSimple example of usage:\n\n```python\nfrom typing import Protocol, final\n\nimport attrs\n# use the \"elegant\" decorator so that the plugin finds classes to check\nfrom pyeo import elegant \n\n\nclass House(Protocol):\n def area(self) -> int: ...\n\n\n@elegant\n@final\n@attrs.define(frozen=True)\nclass HttpHouse(House):\n\n def area(self) -> int:\n return 10\n```\n\n## Contents\n- Principles\n - [No null](#no-null) ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html))\n - [No code in constructors](#no-code-in-constructors) ([why?](http://www.yegor256.com/2014/05/13/why-null-is-bad.html))\n\n - [No getters and setters](#no-getters-and-setters) ([why?](http://www.yegor256.com/2014/09/16/getters-and-setters-are-evil.html))\n \n - [No mutable objects](#no-mutable-objects) ([why?](http://www.yegor256.com/2014/06/09/objects-should-be-immutable.html))\n\n - [No readers, parsers, controllers, sorters, and so on](#no-er-suffix) ([why?](https://www.yegor256.com/2015/03/09/objects-end-with-er.html))\n\n - [No static methods, not even private ones](no-static-methods) ([why?](http://www.yegor256.com/2017/02/07/private-method-is-new-class.html))\n\n - [No instanceof, type casting, or reflection](no-reflection) ([why?](http://www.yegor256.com/2015/04/02/class-casting-is-anti-pattern.html))\n\n - [No public methods without a contract (interface)](#no-public-methods-without-a-contract) ([why?](https://www.yegor256.com/2014/11/20/seven-virtues-of-good-object.html#2-he-works-by-contracts))\n\n - [No statements in test methods except assert](#no-statements-in-tests) ([why?](http://www.yegor256.com/2017/05/17/single-statement-unit-tests.html))\n\n - [No ORM or ActiveRecord](#no-orm) ([why?](https://www.yegor256.com/2014/12/01/orm-offensive-anti-pattern.html) and [why?](https://www.yegor256.com/2016/07/26/active-record.html))\n\n - [No implementation inheritance](#no-inheritance) ([why?](http://www.yegor256.com/2017/01/31/decorating-envelopes.html) and [why?](http://www.yegor256.com/2016/09/13/inheritance-is-procedural.html))\n\n## No null\n\nMypy helps prevent `AttributeError` and other type-related errors by providing static type checking for Python code. It allows specifying variable types, function arguments, and return types to catch potential type issues before the program runs. By using Mypy, developers can identify and fix problems related to attribute access and other type mismatches, leading to improved code quality and easier maintenance.\n\nExample:\n\n```python\nclass Employee(object):\n def __init__(self, user_id: int):\n self._user_id = user_id\n\ndef get_by_id(user_id: int) -> Employee:\n if user_id < 0:\n return None\n return Employee(user_id)\n```\n\nMypy return next violation:\n\n```\nerror: Incompatible return value type (got \"None\", expected \"Employee\") [return-value]\n```\n\nSo, we must use `typing.Optional` or `|` (union) operator.\n\nIt's works:\n\n```\ndef get_by_id(user_id: int) -> Optional[Employee]: ...\ndef get_by_id(user_id: int) -> Employee | None: ...\n```\n\n## No code in constructors\n\nYou can use `@attrs.define` for skip this. It decorator create ctor for your classes automatically. However, we implement check that your primary and secondary ctors not contain code, with the exception of attributes assingment. Please check [NoCodeInCtorFeature](/pyeo/features/no_code_in_ctors.py).\n\n## No getters and setters\n\nActually we realize functional for to prohibit the use of `@property` and `@setter` method decorators. You can use `@attrs.define(frozen=True)` in order to make an object immutable.\n\nProhibit the use of `@property` decorator not protect from evil of getters, so if you can ideas how we can implement more complex check, create issue please.\n\n## No mutable objects\n\n`attrs.define(frozen=True)` is a parameter used in the attrs library to create classes with attributes that cannot be modified after the instance is created (i.e., immutable or \"frozen\" classes).\nThe [attrs](https://www.attrs.org/en/stable/) library allows defining classes using the `@attr.s` decorator or by explicitly calling the `attr.define` function, and `frozen=True` is one of the parameters for specifying attribute behavior in the class. \nWhen you use `attrs.define(frozen=True)` for a class, all its attributes become read-only after the instance is created, making the class \"frozen\" or \"immutable,\" preventing any changes to its attribute values.\n\n## No er suffix\n\nWe check you class name not contain `-er` or `(C|c)lient` suffix by check in [NoErNamesFeature](/pyeo/features/no_er_names.py)\n\n## No static methods\n\nCheck by [NoStaticmethodsFeature](/pyeo/features/no_staticmethods.py)\n\n## No reflection\n\nProhibit next function calls:\n- `isinstance`\n- `type`\n- `issubclass`\n- `hasattr`\n\n## No public methods without a contract\n\nIn Python, `typing.Protocol` is a class introduced in Python 3.8 as part of the typing module. It is used to define structural subtyping or \"duck typing\" for classes, which allows you to create interfaces without using explicit inheritance.\n\n[EachMethodHasProtocolFeature](/pyeo/features/method_has_protocol.py) rule check that all of public class methods has protocol.\n\n## No statements in tests\n\nTODO\n\n## No ORM\n\nDetect using ORM or ActiveRecord tools on project by design/code review\n\n## No inheritance\n\nEach `@elegant` object must be `typing.final`. Check by [FinalClassFeature](/pyeo/features/final_object.py)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pyeo is an advanced static analysis tool tailored specifically to enforce the principles advocated by Elegant Objects (elegantobjects.org) in Python projects. It serves as a quality control instrument to ensure that your Python code adheres to the core tenets of elegance, simplicity, and maintainability.",
"version": "0.0.1a16",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d8651909084fcf39338d27cfb6fd453d41d183b4476096625d3bae7e3e45f24c",
"md5": "bcd5c37fdf08e7bc983dc3833ad0cfd9",
"sha256": "4ad0ea8748cfbc7ba1eb3e08263c14362682c283176f0765ec28b416ec70aa74"
},
"downloads": -1,
"filename": "eo_styleguide-0.0.1a16-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bcd5c37fdf08e7bc983dc3833ad0cfd9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 15486,
"upload_time": "2024-12-05T10:28:34",
"upload_time_iso_8601": "2024-12-05T10:28:34.311253Z",
"url": "https://files.pythonhosted.org/packages/d8/65/1909084fcf39338d27cfb6fd453d41d183b4476096625d3bae7e3e45f24c/eo_styleguide-0.0.1a16-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "19f5ec9370830a96e59cdbde2f52ebb6984f8e6daedb742b066b56a399aeaff9",
"md5": "8709b5f0a57fb18ef29ac567b8c9d424",
"sha256": "8a9d8de00677f7b614c6a063325cc56fe15aa0d608ede34c9f3450459e592249"
},
"downloads": -1,
"filename": "eo_styleguide-0.0.1a16.tar.gz",
"has_sig": false,
"md5_digest": "8709b5f0a57fb18ef29ac567b8c9d424",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 9473,
"upload_time": "2024-12-05T10:28:35",
"upload_time_iso_8601": "2024-12-05T10:28:35.394815Z",
"url": "https://files.pythonhosted.org/packages/19/f5/ec9370830a96e59cdbde2f52ebb6984f8e6daedb742b066b56a399aeaff9/eo_styleguide-0.0.1a16.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-05 10:28:35",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "eo-styleguide"
}