[Python-3000] Traits/roles instead of ABCs

Raymond Hettinger python at rcn.com
Mon Apr 30 06:05:28 CEST 2007


[Collin Winter]
> Put another way, a role is an assertion about a set of capabilities.
 . . .
> If there's interest in this, I could probably whip up a PEP before the deadline.

+100 I'm very interested in seeing a lighter weight alternative to abc.py that:

1) is dynamic
2) doesn't require inheritance to work
3) doesn't require mucking with isinstance or other existing mechansims
4) makes a limited, useful set of assertions rather than broadly covering a whole API.
5) that leaves the notion of duck-typing as the rule rather than the exception
6) that doesn't freeze all of the key APIs in concrete

I'm concerned that the current ABC proposal will quickly evolve from optional
to required and create somewhat somewhat java-esque landscape where
inheritance and full-specification are the order of the day.

IMHO, the ABC approach is using a cannon to shoot a mosquito.  My day-to-day
problems are much smaller are could be solved by a metadata attribute or a
role/trait solution:

* knowing whether a __getitem__ method implements a mapping or a sequence
* knowing whether an object can have more that one iterator (i.e a file has one
   but a list can have many)
* knowing whether a sequence, file, cursor, etc is writable or just readonly.


Raymond



More information about the Python-3000 mailing list