I have a wrapper around DB which provides some utility methods. An instance of DB wrapper is created once and accessible from a base class. I want to reuse this instance in a helper class, and was thinking about dependency injection due to my experience with OOP like C# or Java. However, with python I seem to lose intellisense support when I do this. I saw examples of dependency injection per function, however, this does not work for me, since a wrapper class has many different functions I want to use. What is the Python-ic way of achieving this?
Asked
Active
Viewed 127 times
1 Answers
0
The pythonic way is probably to pass the resource class as a parameter and rely on duck-typing... (you could probably create an abstract base class and multiply inherit it as a mixin to demonstrate that you know about interfaces, but if you want that kind of pain you probably shouldn't be coding in Python... ;-)

thebjorn
- 26,297
- 11
- 96
- 138
-
The problem is the intellisense support, which I lose if I just pass a class as a parameter :( – oldbam Oct 07 '13 at 13:27
-
What if you use an argument with a default value? e.g. `(..., resourceA=MyClass)` – thebjorn Oct 07 '13 at 13:58
-
Then the callers may think that they are not required to provide a value, even though they are – oldbam Oct 07 '13 at 14:11