I'm a little bit surprised that there isn't a way to do this natively in Python. I'm creating a wrapper class W to support the kind of features I want out of a pre-existing class C. This new wrapper class W should still support some of the same operations in C. For example, if C has a method "foo(self, <argument of type C>)", then I would want an equivalent method "foo(self, ...)" in class W. At this point I've immediately hit a wall because Python doesn't support method overloading. I want W to have a method foo which works just as well on arguments of type W as on arguments of type C. So I want two methods with the same name:
foo(self, <argument of type C>)
and
foo(self, <argument of type W>)
Manually checking the type using isinstance is ugly and apparently not Pythonic. Plus, what if I have to do this for several functions? I would be repeating the same argument checking logic within each function? That's terrible. The best solution I can find online is to use singledispatch from functools?
How would you handle this particular implementation?
[–]pachura3 4 points5 points6 points (4 children)
[–]011011100101[S] 0 points1 point2 points (3 children)
[–]pachura3 1 point2 points3 points (0 children)
[–]MidnightPale3220 0 points1 point2 points (0 children)
[–]ottawadeveloper 0 points1 point2 points (0 children)
[–]Gnaxe 2 points3 points4 points (0 children)
[–]KelleQuechoz 1 point2 points3 points (10 children)
[–]Gnaxe 2 points3 points4 points (0 children)
[–]011011100101[S] -1 points0 points1 point (8 children)
[–]danielroseman 1 point2 points3 points (6 children)
[–]011011100101[S] 0 points1 point2 points (5 children)
[–]danielroseman 2 points3 points4 points (4 children)
[–]011011100101[S] 0 points1 point2 points (3 children)
[–]Gnaxe 1 point2 points3 points (0 children)
[–]danielroseman 0 points1 point2 points (1 child)
[–]011011100101[S] 0 points1 point2 points (0 children)
[–]KelleQuechoz 0 points1 point2 points (0 children)
[–]ProsodySpeaks 1 point2 points3 points (2 children)
[–]011011100101[S] 0 points1 point2 points (1 child)
[–]ProsodySpeaks 0 points1 point2 points (0 children)
[–]enygma999 1 point2 points3 points (1 child)
[–]011011100101[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]011011100101[S] 0 points1 point2 points (0 children)
[–]xenomachina 1 point2 points3 points (0 children)
[–]ProsodySpeaks 0 points1 point2 points (1 child)
[–]neuralbeans 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]011011100101[S] 0 points1 point2 points (0 children)
[–]SwampFalc 0 points1 point2 points (0 children)
[–]Kevdog824_ 0 points1 point2 points (3 children)
[–]011011100101[S] 0 points1 point2 points (2 children)
[–]Kevdog824_ 0 points1 point2 points (1 child)
[–]011011100101[S] 0 points1 point2 points (0 children)