[Python-Dev] in a pickle: method lookup irregularities (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sun Feb 17 05:42:18 CET 2013
- Previous message: [Python-Dev] in a pickle: method lookup irregularities
- Next message: [Python-Dev] Fwd: PEP 426 is now the draft spec for distribution metadata 2.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Feb 17, 2013 at 1:36 PM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
(See http://bugs.python.org/issue16251)
The pickle module looks up special methods on instances rather than using the behavior described in the language reference (or even just looking them up on the class). This means that custom getattribute() and getattr() implementations may get triggered (e.g. if there is no reduce() implemented). Bringing pickle in sync with the language reference would not involve a big change, but it would impact anyone that relies on the current behavior. Most notably, proxy types could exist which leverage the current semantics. I look at this as trading one "bug" for another in a . So I want to get some general feedback on the situation and see what others consider to be the trade-offs of fixing or not fixing this bug. I'm particularly interested in existing cases where code uses the current behavior. With that in hand we could assess what alternatives exist in those cases or how we could better document workarounds for the current behavior.
I vaguely recall some discussions about this and other similar cases of metaclass confusion (perhaps related to the copy module).
One possible approach is to look specifically for cases where type(obj) != obj.class and handle them differently.
The general trend has been towards more consistently ignoring instance attributes when looking up special methods, but you're right that this can be a backwards compatibility minefield.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] in a pickle: method lookup irregularities
- Next message: [Python-Dev] Fwd: PEP 426 is now the draft spec for distribution metadata 2.0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]