[Python-3000] PEP 3119 - Introducing Abstract Base Classes (original) (raw)
Barry Warsaw barry at python.org
Tue May 1 01:06:11 CEST 2007
- Previous message: [Python-3000] super(), class decorators, and PEP 3115
- Next message: [Python-3000] PEP 3119 - Introducing Abstract Base Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Apr 27, 2007, at 1:10 PM, Jim Jewett wrote:
On 4/27/07, Barry Warsaw <barry at python.org> wrote:
- - Attributes. Interfaces allow you to make assertions about attributes, not just methods, while ABCs necessarily cover only methods. Why can't they have data attributes as well?
They can /have/ data attributes, but that's not really the point.
The point (IMHO) is that such attributes can be documented,
inspected, and reasoned about. You could annotate interface
attributes with type information in order to automatically generate
database tables or web forms, etc. Normal Python attributes can't do
that, although if they were properties, they could.
- - With interfaces, you can make assertions about individual objects which may be different than what their classes assert. Interface proponents seem to care a lot about this and it seems there are valid uses cases for it. Isn't this something that could be handled by overriding isinstance?
It could.
Another example of separating inheritance and interface comes up when you want to derive a subclass to share implementation details, but you want to subtly change the semantics, which would invalidate an ABC claim by the base class. Something like a GrowOnlyDictionary that derived from dict for implementation purposes, but didn't want to implement delitem as required by the MutableMapping ABC. OK, that makes the isubclass override trickier, so there should be an example, but I think it can still be done.
Finally, I'm concerned with the "weight" of adding ABCs to all the built-in types. What if the builtin types did not initially derive from any ABC, but were added (through an issubclass override) when the abc module was imported?
That would allow for some unfortunately global side-effects. Say I
happen to import your library that imports abc. Now all the built-in
types in my entire application get globally changed. I'm also not
sure how you'd implement that.
Cheers,
- -Barry
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin)
iQCVAwUBRjZ2ZHEjvBPtnXfVAQJMYgP+PiEvTRe+AeQHJSjYfx3kxE3oV+n9kfbL xns+fK6Chub+frAzcHz+an7GXikTxbdYHysunWqhpB0TSOZfF7SzKNgD3pHTKmN/ zyMVTykr5zynmLPi8bygZfTNlm340Qrc+ymE3qjCsbRP9XZtFC5CJYmlIM2kU0MI HMV5KtXjbgc= =77iN -----END PGP SIGNATURE-----
- Previous message: [Python-3000] super(), class decorators, and PEP 3115
- Next message: [Python-3000] PEP 3119 - Introducing Abstract Base Classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]