Law of Demeter and Python

Is there a tool to verify that Python code complies with the Demeter law?

I found a mention of Demeter in pychecker, but it seems that the tool understands this law different from what I expect: http://en.wikipedia.org/wiki/Law_of_Demeter

Wikipedia definition: Demeter's law for functions requires that the method M of an object O can only call methods of the following types of objects:

  • O myself
  • M parameters
  • any objects created / created in M
  • O direct component objects
  • global variable available O in area M
+3
source share
3 answers

, , , . , , . .

+1

... M O :

  • O - self. .
  • M - , . , locals()
  • , / M - . , locals()
  • O - .. self.
  • , O, M - , global , . globals().

Ummm.... , , ? - , , .

Python, ?

?

0

You may violate this law as follows:

class SomeClass:
    def someMethod(self):
        self.getSomeOtherClass().someOtherMethod() # this breaks the law
    def getSomeOtherClass(self):
        class_ = SomeOtherClass()
        return class_

Or not?

0
source

Source: https://habr.com/ru/post/1770692/


All Articles