How to fake type with Python

前端 未结 6 810
生来不讨喜
生来不讨喜 2020-12-10 12:04

I recently developed a class named DocumentWrapper around some ORM document object in Python to transparently add some features to it without changing its inter

6条回答
  •  眼角桃花
    2020-12-10 12:50

    The best way is to inherit DocumentWrapper from the User itself, or mix-in pattern and doing multiple inherintance from many classes

     class DocumentWrapper(User, object)
    

    You can also fake isinstance() results by manipulating obj.__class__ but this is deep level magic and should not be done.

提交回复
热议问题