Skip to main content

made-with-python Build Status Coverage Status Code style: black Checked with pylint Checked with flake8 Checked with pydocstyle Checked with mypy License EO principles respected here PyPI version shields.io PyPI pyversions CodeFactor PyPi downloads Downloads

Enforce PEP-8

Package allows to enforce certain kinds of PEP-8 convention coding styles (or perform overall code diagnostics). It aims to help maintain programmers sanity while making any code changes. In large object-oriented programs, it can sometimes be useful to put class definitions under control of a metaclass that are used to alert programmers to potential problems.

Most important that package enforces you to write clear and concise pythonic code.

Tools

Production

  • python 3.6, 3.7, 3.8, 3.9

Development

Usage

Installation

Please run following script to obtain latest package from PYPI:

pip install enforce-pep8
✨ 🍰 ✨

Quick start

Bad class name: lowercase class name is defined

from punish.style import AbstractStyle


class stylish(AbstractStyle):
     def name(self) -> None:
         pass

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  punish.style.BadClassNameError
Class name 'stylish' specified in lowercase. Consider to use camelcase style!

Bad attribute name: camelcase method name is defined

from punish.style import AbstractStyle


class Stylish(AbstractStyle):
     def showName(self) -> None:
         pass

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  punish.style.BadAttributeNameError
Bad attribute name is specified: 'Stylish:showName'. Consider to use lowercase style: 'Stylish:showname'! 

Bad method signature: method signature mismatch within base and child classes

from punish.style import AbstractStyle


class Stylish(AbstractStyle):
     def show(self, indent: str = ":") -> str:
         pass


class SoStylish(Stylish):
    def show(self, indent: str = ":", not_expected_argument: bool = False) -> str:
        pass

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  punish.style.SignatureError
Signature mismatch in 'SoStylish.show', 
(self, indent: str = ':') -> str != (self, indent: str = ':', not_expected_argument: bool = False) -> str 

Duplicated attribute name: defined two methods with same name

from punish.style import AbstractStyle


class Stylish(AbstractStyle):
    def name(self) -> None:
        pass

    def name(self) -> None:
        pass

Traceback (most recent call last):
  File "<stdin>", line 5, in Stylish
punish.style.DuplicateAttributeError: 'name' attribute is already defined in 'Stylish' class

Bad argument type: not expected type is passed to the argument

from punish.type import OrderTypedMeta, String, Typed


class Car(metaclass=OrderTypedMeta):
    color: Typed = String()
 
    def __init__(self, color: str) -> None:
        self.color = color


car: Car = Car(color=23)

Traceback (most recent call last):
  File "<stdin>", line 5, in __init__
TypeError: Expected '<class 'str'>' type for 'color' attribute

Bad setter type: not expected type for setter argument

from punish.type import typed_property


class Person:
    name: property = typed_property("name", str)
    age: property = typed_property("age", int)

    def __init__(self, name: str, age: int) -> None:
        self._name = name
        self._age = age


person: Person = Person(name="Luke", age=22)
person.age = None

Traceback (most recent call last):
  File "<stdin>", line 5, in __init__
TypeError: 'age' argument must be a '<class 'int'>' type

Frozen class attributes: it is forbidden to modify class attributes

from punish.type import FrozenMeta


class Bio(metaclass=FrozenMeta):
    name: str = 'Luke'
    company: str = 'Cisco'


bio = Bio()
bio.name = 'Amir'
dataclasses.FrozenInstanceError: cannot assign to field 'name'

Source code

git clone git@github.com:vyahello/enforce-pep8.git
pip install -e .

Or using direct source:

pip install git+https://github.com/vyahello/enforce-pep8@0.0.1

⬆ back to top

Development notes

Testing

Please execute command below to run unittests with pytest tool:

pytest

CI

Project has Travis CI integration using .travis.yml file thus code analysis (black, pylint, flake8, mypy, pydocstyle) and unittests (pytest) will be run automatically after every made change to the repository.

To be able to run code analysis, please execute command below:

./analyse-source-code.sh

Release notes

Please check changelog file to get more details about actual versions and it's release notes.

Meta

Author – Volodymyr Yahello. Please check authors file for more details.

Distributed under the MIT license. See LICENSE for more information.

You can reach out me at:

Contributing

I would highly appreciate any contribution and support. If you are interested to add your ideas into project please follow next simple steps:

  1. Clone the repository
  2. Configure git for the first time after cloning with your name and email
  3. pip install -r requirements.txt to install all project dependencies
  4. pip install -r requirements-dev.txt to install all development project dependencies
  5. Create your feature branch (git checkout -b feature/fooBar)
  6. Commit your changes (git commit -am 'Add some fooBar')
  7. Push to the branch (git push origin feature/fooBar)
  8. Create a new Pull Request

What's next

Project is inspired mainly by pythonic PEP8 code style reflected at https://www.python.org/dev/peps/pep-0008. Also decent ideas are described in https://github.com/zedr/clean-code-python project.

In general, future releases will contain API implementations from mentioned style guides above.

All recent activities and ideas are described at project issues page. If you have ideas you want to change/implement please do not hesitate and create an issue.

⬆ back to top

Release files for enforce-pep8 0.0.12

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

Built distribution (wheel)

Table of built distributions (wheels) for enforce-pep8 0.0.12
File Interpreter ABI Platform
enforce_pep8-0.0.12-py3-none-any.whl Python 3 none any Details

Release files / enforce_pep8-0.0.12-py3-none-any.whl

Download URL enforce_pep8-0.0.12-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0678d3a895b19591dc8b1400695412be7bec0b5bb0df83a18c9498c37cf47a3
BLAKE2b-256 checksum
How to use checksums
99135443f0a7784677366d69f72c2957f48984cd8a41c2dabbcac44fd75f335a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.2

Release history Release notifications | RSS feed

This release

0.0.12 This release

1 release file

0.0.10

2 release files

0.0.9

3 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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