
On Sun, Apr 03, 2022 at 07:24:42PM -0000, Brian McCall wrote:
Let's say we have one of your class-ical ( :D ) geometrical shapes hierarchy, including an abstract Shape class.
``` class Shape(abc.ABC): @abc.abstractmethod def area(self): """"""
The rest of your code sample only shows single inheritence, so it is doubtful that the issues you had were related to the issues in this thread.
In my mind, the best way to make the code work, and promote use and contribution to it, is to make it so that users can pass in callables instead of fixed values to __init__, and the machinery that returns an object will create properties to represent that value if it is a callable, otherwise attributes as shown above.
That sounds like a convoluted solution, but maybe I don't understand your requirements.
I will not detail my solution here, but if you know how properties work, then you know that this solution requires classes to be generated on the fly.
I thought I understood how properties work, but I didn't know (and still don't) that this solution requires classes to be generated on the fly. Does that imply that every shape instance has its own unique class?
This problem was a tough nut to crack
Perhaps I don't understand your requirements, but this sounds like a trivial nut to crack. Put the logic in your properties: @property def radius(self): r = self._radius if callable(r): return r() else: return r Although I'm not sure why you want the radius of a shape to be a callable in the first place. Seems all very over-engineered. Anyway, there's nothing in your description here that hints as to how or why super() is an issue, except in the sense that you're doing Complicated Things™ with metaclasses, `__new__`, dynamically-generated classes, ABCs, properties, and very possibly the Philosopher's Stone *wink*, so I'm not surprised you ran into difficulties. By the way, what super does is explained in fine detail here: https://www.python.org/download/releases/2.3/mro/ I know, I know, who goes looking through the docs for Python 2.3 for current features??? But you get to that link via the glossary entry for "method resolution order". -- Steve