How to fake type with Python

前端 未结 6 811
生来不讨喜
生来不讨喜 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:49

    It sounds like you want to test the type of the object your DocumentWrapper wraps, not the type of the DocumentWrapper itself. If that's right, then the interface to DocumentWrapper needs to expose that type. You might add a method to your DocumentWrapper class that returns the type of the wrapped object, for instance. But I don't think that making the call to isinstance ambiguous, by making it return True when it's not, is the right way to solve this.

提交回复
热议问题