I have a scenario where I've got multiple nested classes all with the same name, and debugging it is driving me nuts.
Here's a sketch:
class Reference(object):
# common functionality here
class Fruit(object):
# common functionality here
class Apple(Fruit):
class Ref(Reference):
# specific functionality here
class Orange(Fruit):
class Ref(Reference):
# specific functionality here
# like 6 more fruits
My problem: any operation that lists the classname of a reference object shows it as mymodule.Ref and not, say, mymodule.Apple.Ref, which would be much more helpful.
Is there a way to tell Python to use a better name for instances of my nested classes? in default __str__ but also in __type__, etc.
Bonus details:
- flattening the class structure and/or using unique names would do it, but (a) that adds namespace clutter, and (b) there are bits in Fruit that use
cls.Ref/self.Ref. Suboptimal. - it's a legacy 2.7 research system, if that matters. Actually, if 3 has fixed this that would be a useful addition to my bucket of arguments to upgrade us...