[Python-Dev] Semantic of isinstance (original) (raw)
Phillip J. Eby pje at telecommunity.com
Tue Jun 27 15:53:07 CEST 2006
- Previous message: [Python-Dev] Semantic of isinstance
- Next message: [Python-Dev] Semantic of isinstance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 09:29 AM 6/27/2006 +0200, Maric Michaud wrote:
Le mardi 27 juin 2006 05:38, Phillip J. Eby a écrit : > As it happens, this is due to the fact that E is a type, while E() is > not. There's an optimization in the isinstance() machinery that simply > checks to see if D().class is a subtype of E. That's where your > experiment fails. > > I'm not sure whether this behavior should be considered correct or not. >
Doesn't seems to be just related to isinstance implementation,
That may be, but it's due to code that's entirely independent. isinstance() does what it does independently of the behavior you describe below, which is a product of how descriptors behave in new and old-style classes. The behavior you describe below is a natural consequence of the documented behavior of descriptors, while the above behavior is a performance optimization in isinstance(). They aren't related.
furthermore, it is very surprising that old-style and new style classes behave exactly the opposite way.
In [2]: class a(object) : ...: class = 0 ...: ...: In [3]: a.class Out[3]: <type 'type'> In [4]: a().class Out[4]: 0 In [7]: class a : ...: class = 0 ...: ...: In [8]: a.class Out[8]: 0 In [9]: a().class Out[9]: <class _main_.a at 0xa78cb4ac>
- Previous message: [Python-Dev] Semantic of isinstance
- Next message: [Python-Dev] Semantic of isinstance
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]