On 4/25/07, Jim Jewett <[EMAIL PROTECTED]> wrote:
On 4/25/07, Emin.shopper Martinian.shopper <[EMAIL PROTECTED]> wrote: > I think a bigger issue is whether to check at definition time or check at > instantiation time. It seems to me the former has the benefit of catching > errors earlier and potentially saving time. I don't immediately see the > advantage of the latter (probably that is due to my lack of imagination). The advantage of waiting is that you can *have* (partially) abstract classes. So long as you never instantiate them directly (super calls are OK), everything is fine.
Good point. However, you can do this without precluding def time checks. For example, you can have any class which has abstract methods not be forced to satisfy parent ABC rules since it is still abstract, or you can provide another way to mark the class as partially abstract (my initial implemenation does this by having the partially abstract class inherit from both the parent abstract class and the class that all abstract classes inherit from). You could reasonably argue that the benefit of def time enforcement is outweighed by the need to do something special for a class that inherits from an abstract base class but has no abstract methods itself. If you want an earlier check, then just create an instance of your
class at import time (or, alternatively, in your unit tests). If it can be created, it passed the test.
Yes, I could do that assuming that the inputs to the class __init__ method can be constructed quickly. Personally, I would find it preferable to have to do something slightly different for partially abstract classes with no abstract methods, but I guess it's a matter of taste. -Emin
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com