I noticed that the sqlite3
-library still uses the __conform__
-method to adapt objects for storage in a database.
Then you need to give your class a method
__conform__(self, protocol)
which must return the converted value.
This seems to follow PEP 246, which specifies the __conform__
-method, but it has been rejected;
I'm rejecting this PEP. Something much better is about to happen; it's too early to say exactly what, but it's not going to resemble the proposal in this PEP too closely so it's better to start a new PEP. GvR.
^ Rejection notice of PEP 246 ^
Now, how can it be that an official Python library implements a standard that has been defined in a suggestion that has explicitly been rejected?
PEP 246 was a suggestion to implement a particular design pattern (testing if an incoming object adhered to a given protocol) using a particular name. The proposal, if accepted, would have added a new special method to the Python language (__conform__
), as well as a new built-in function (adapt
).
The PEP decision simply rejected standardization. It does not prohibit any Python package designers from creating and using such a pattern/naming convention internally in their code. This is analogous to the freedom the sqlite3 developers have in naming the Cursor
method fetchone()
rather than fetchnext()
. They can name/design their package components however they like, within reason and utility.
Update - according to Eric Snow, regarding the 'something much better' that was promised to be coming:
At the time it referred to generic functions (a la PEP 3124: Overloading, Generic Functions, Interfaces, and Adaptation). However, ultimately it was Abstract Base Classes (PEP 3119) that slid into this space.