On Mon, Apr 04, 2022 at 08:28:31AM +1000, Chris Angelico wrote:

> What do you intend for dependency injection to do with this scream
> method? What would make sense? You've already designed something that
> works differently.

I don't know why malmiteria keeps talking about dependency injection. 
None of his examples show dependency injection.

https://www.jamesshore.com/v2/blog/2006/dependency-injection-demystified

In Python, dependency injection is usually called "passing an object to 
the constructor".

# No dependency injection.
class Car:
    def __init__(self):
        self.engine = Engine()


# With dependency injection.
class Car:
    def __init__(self, engine):
        self.engine = engine


mycar = Car(Engine())
test_car = Car(MockEngine())

With duck typing, the car's dependency, the engine, doesn't have to be 
an instance of Engine. It can be anything that quacks like an engine: a 
proxy, a mock engine, a thousand hamsters in wheels, whatever you want 
to pass in as the dependency, so long as it has the right interface.

In the design pattern world, millions of words have been written about 
this. (The DP folks love to over-engineer their code.) In Python, we 
just call it passing in an object :-)

In any case, it has nothing to do with super or the MRO.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UBEXOAP34YKAP5AIP5G6LKKUW5EJRHQM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to