Skip to main content

pyeo

EO principles respected here

wemake-python-styleguide Hits-of-Code

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.

The project is inspired by the team that made fun of me because of the lego build. STT lambda ❤️️

pip install eo-styleguide

Simple example of usage:

from typing import Protocol, final

import attrs


class House(Protocol):
    def area(self) -> int: ...


@final
@attrs.define(frozen=True)
class HttpHouse(House):

    def area(self) -> int:
        return 10
mypy file.py && flake8 file.py

Contents

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:

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 CodeFreeCtorVisitor.

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 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.

See NoMutableObjectsVisitor

No er suffix

We check you class name not contain -er or (C|c)lient suffix by check in NoErNamesFeature

No static methods

A static method is a procedure that happens to live in a class: there is no object behind it, so everything it works on arrives as arguments, which is exactly what objects exist to hide. A private method is no better: it is an object that never got a class of its own.

PEO400 reports every method decorated with @staticmethod, synchronous or async. Private methods are reported as NPM100 by flake8-no-private-methods, which comes with pyeo.

No reflection

An object should be asked to do something, not asked what it is: a check of its type makes the caller decide on its behalf, and every new type means one more branch in someone else's code.

PEO700 reports, everywhere in the code:

  • calls to isinstance, issubclass, hasattr, getattr, setattr and delattr
  • type with one argument; type(name, bases, namespace) builds a class and stays allowed
  • typing.cast and cast
  • class patterns of match statements, such as case list():

Where reflection cannot be avoided, say so with # noqa: PEO700 on that line.

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.

flake8-override plugin 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 class must be typing.final. Check by flake8-final

Metadata

Release files for eo-styleguide 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eo-styleguide 0.2.0
File Size Uploaded Provenance Actions
eo_styleguide-0.2.0.tar.gz 13.5 kB Without provenance Details for eo_styleguide-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eo-styleguide 0.2.0
File Interpreter ABI Platform Actions
eo_styleguide-0.2.0-py3-none-any.whl Python 3 none any Details for eo_styleguide-0.2.0-py3-none-any.whl

Total release size: 30.0 kB

Release files / eo_styleguide-0.2.0.tar.gz

Download URL eo_styleguide-0.2.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b7acb2c99446daef44fe0deef11ffac803a4101d05c78d14b9e4914d1a4a63fb
BLAKE2b-256 checksum
How to use checksums
07689a73fcca6354faeae661083b6bc168169f6bdf5f4f6900490b87319aebd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.1 Linux/7.0.0-1017-azure

Release files / eo_styleguide-0.2.0-py3-none-any.whl

Download URL eo_styleguide-0.2.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b535a3c14698c4a679ca33cf03dae8a26307a1ef9f8d587b41ede4498647512c
BLAKE2b-256 checksum
How to use checksums
87521fa91a456671e3b12090fced3f91c544440f03baf7ad4bf7df10ef506251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.1 Linux/7.0.0-1017-azure

Security for eo-styleguide 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page