Message197755
Issue 10006 pointed out that attempting to access object.__abstractmethods__ raises AttributeError. The solution was to ensure type.__abstractmethods__ *also* raises AttributeError.
This is thoroughly confusing, since the name is clearly visible in the output of dir(type). While it's technically legal for a descriptor to always raise AttributeError, breaking the following typical assumed invariant is *highly* dubious:
all(hasattr(obj, x) for x in dir(obj))
I see three main alternatives for improving the situation:
1. Make __abstractmethods__ a read-only descriptor that returns something meaningful (like a frozenset(), the same as you get if you inherit from abc.ABCMeta without defining any abstract methods)
2. Throw a better exception message that explains the broken invariant rather than the generic "AttributeError with attribute name" that is currently thrown.
3. Implement type.__dir__ to filter out the uncooperative descriptor |
|
Date |
User |
Action |
Args |
2013-09-15 07:33:28 | ncoghlan | set | recipients:
+ ncoghlan |
2013-09-15 07:33:28 | ncoghlan | set | messageid: <1379230408.43.0.525404043988.issue19022@psf.upfronthosting.co.za> |
2013-09-15 07:33:28 | ncoghlan | link | issue19022 messages |
2013-09-15 07:33:27 | ncoghlan | create | |
|