[Python-ideas] Adding`Unpicklable` to the `collections` module
Nick Coghlan
ncoghlan at gmail.com
Wed Dec 1 01:57:38 CET 2010
More information about the Python-ideas mailing list
Wed Dec 1 01:57:38 CET 2010
- Previous message: [Python-ideas] Truly international Python
- Next message: [Python-ideas] Adding`Unpicklable` to the `collections` module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Dec 1, 2010 at 8:08 AM, Masklinn <masklinn at masklinn.net> wrote: >> That’s why isintance+ABCs is the right test to use here. See >> http://docs.python.org/dev/reference/datamodel#special-method-names > Due to Python's lookup rule, looking up most (if not all) of the special method on the instance is going to give the same result. It's the "most" in that sentence that makes the ABC the more accurate check of the examples given. Checking the instance does work most of the time (since most instances don't have magic methods attached) but fails abysmally when the instance in question is a class and the intent is to invoke the magic methods of the metaclass (usually 'type'). Deliberately bypassing the instance with either type(x) or x.__class__ is the closest pure Python code can get to correctly following the special method lookup rules: http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-ideas] Truly international Python
- Next message: [Python-ideas] Adding`Unpicklable` to the `collections` module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list