Skip to main content

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.

Project description

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

TODO

No reflection

TODO

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eo_styleguide-0.1.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eo_styleguide-0.1.1-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file eo_styleguide-0.1.1.tar.gz.

File metadata

  • Download URL: eo_styleguide-0.1.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for eo_styleguide-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8c681325a7c2a4f7f8ee2d41ba5f06fff93cfaa23698d26de52f2b3a5c2bd2a8
MD5 6a836588a3b563515b0444c4037959c2
BLAKE2b-256 0ac790bdba7574e2a29f792299552eb357947c0dc33e88d1b254aaacb8820a73

See more details on using hashes here.

File details

Details for the file eo_styleguide-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: eo_styleguide-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.1 Linux/6.11.0-1018-azure

File hashes

Hashes for eo_styleguide-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 96760b1f3727b151ee55cce514d286478ff4468d906b1f11b2b0c593691173a0
MD5 b02229663eeb389ddbd1933a03a7b12d
BLAKE2b-256 ea583032e9f694cddc86dfaf59f325ebc0ca447c796951572f92509f6d2b879f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page