faif / python-patterns

A collection of design patterns/idioms in Python
40.2k stars 6.93k forks source link

#415 linter preventing prs #417

Closed grimley517 closed 3 months ago

grimley517 commented 4 months ago

A collection of small changes to comply with lining rules.

Also added folders - dist and build to the .gitignore. These are generated in the CI pipeline. adding to gitignore prevents a user from accidentally committing these whilst working through pipeline.

grimley517 commented 4 months ago

addresses issue #415

grimley517 commented 4 months ago

In relation to patterns/behavioral/strategy.py

On adding the additional spaces required for flake linter to work, the line became too long.

$ flake8 . --count --show-source --statistics
./patterns/behavioral/strategy.py:59:121: E501 line too long (121 > 120 characters)
        return f"<Order price: {self.price} with discount strategy: {getattr(self.discount_strategy, '__name__', None)}>"
                                                                                                                        ^
1     E501 line too long (121 > 120 characters)

Hence changed to multiline comment

grimley517 commented 4 months ago

Multiline string fails as generates blank lines.

Extract lengthy call to variable - works better anyway as breaks up cognitive load of line

grimley517 commented 4 months ago

The last commit isn't really within the scope of the issue.

By extracting the linting and testing to an external script it is easier for developers to run this prior to deployment and see issues.

The linting and testing is still incomplete.
4 tests still fail. But these are beyond simple linting and should be discussed separately.

FAILED patterns/creational/abstract_factory.py::patterns.creational.abstract_factory.main
FAILED patterns/dependency_injection.py::patterns.dependency_injection.main
FAILED patterns/fundamental/delegation_pattern.py::patterns.fundamental.delegation_pattern.Delegator
FAILED patterns/other/blackboard.py::patterns.other.blackboard.main
============================================================================================== 4 failed, 98 passed in 0.29s ==============================================================================================
grimley517 commented 4 months ago

Willing to convert lint script to powershell or remove if requested.

I'll also write up the remaining test failures into new issues through the week.

grimley517 commented 4 months ago

Raised #418 for first failing test.

grimley517 commented 4 months ago

Issue #418 is addressed here.

Its addressed here rather than in its own PR as the pipeline is unblocked. Raising in its own PR would require this branch to be pulled with a failing pipieline.

grimley517 commented 4 months ago
FAILED patterns/dependency_injection.py::patterns.dependency_injection.main

This is due to a method being called which isn't there. Much more straightforward than the factory pattern error.