wemake-services / wemake-services/wemake-python-styleguide

Forbids classes with too high coupling

Open
#1,242 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

level:advanced question rule request
Dominant language
Python
Stars
2.9k
Forks
430
Avg merge
5h 14m
Merged PRs (30d)
34

Description

Rule request

Thesis

Coupling is a very important concept in programming.

Currently, we don't enforce any rules about cohesion and coupling. But, we totally need to!

And while you can use https://github.com/mschwager/cohesion to measure cohesion, there's no tool to measure coupling.

I don't think that cohesion is important. Because the best class in my opinion is @dataclass:

@dataclass
def Some(object):
    field1: int
    field2: str

But, coupling is the whole other beast! High coupling makes refactoring very hard. Compare these two samples:

class SomeClass(ParentClass):
     def method(self, other):
          if other.some_field > other.other_field:
               other.first_method()
          else:
               other.other_method()

And:

class SomeClass(ParentClass):
     def method(self, other):
         other.smart_method()

The second one is way better.

Problems:

  1. I am not sure how to count coupling
  2. I am not sure about corner values

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by deciding how coupling should be counted and what corner values mean, then locate the existing rule structure and add tests for the agreed thresholds. Done means a documented, deterministic coupling rule with tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.