2

Say I have a class like this:

class Wrapper(object):
    def __init__(self, obj):
        self.__obj = obj

    def __getattr__(self, name):
        logger.debug('Accessing %s', name)
        return getattr(self.__obj, name)

Elsewhere in the codebase are generic functions using the @singledispatch decorator. I'd like for "wrapped" instances to act like they were never wrapped. So for example, pprint(Wrapper({})) will operate like pprint({})

How can I accomplish this?

Dan Passaro
  • 4,211
  • 2
  • 29
  • 33
  • 2
    Hmm, I can tell this will be pretty difficult because stdlib singledispatch works on the type. No matter how transparent you can make the wrapper, I don't know a way to lie about its type. – wim May 15 '19 at 18:07

0 Answers0