[Python-bugs-list] [ python-Bugs-467267 ] isinstance depends on import form (original) (raw)
noreply@sourceforge.net noreply@sourceforge.net
Tue, 02 Oct 2001 12:26:19 -0700
- Previous message: [Python-bugs-list] [ python-Bugs-467267 ] isinstance depends on import form
- Next message: [Python-bugs-list] [ python-Bugs-467253 ] license points to the wrong file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bugs item #467267, was opened at 2001-10-02 11:56 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467267&group_id=5470
Category: Python Interpreter Core Group: Python 2.1.1 Status: Open Resolution: None Priority: 5 Submitted By: Luis P Caamano (lcaamano) Assigned to: Nobody/Anonymous (nobody) Summary: isinstance depends on import form
Initial Comment: isinstance(obj, cls) fails if cls is in a package and the import line of the obj creator is different from the import line in the code calling isinstance.
It seems to me that the problem is the address test in PyObject_IsInstance(), because different import forms produce objects with different addresses.
A limited workaround would be to test for class name but that doesn't include subclasses or types. So, instead of:
if isinstance(obj, class):
use
if obj.class.name == 'classname':
-------Sample--------------------
Python 2.1.1 (#2, Jul 25 2001, 17:54:11) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2 Type "copyright", "credits" or "license" for more information.
from spam.eggs import SpamAndEggs import spam.eggs '0x%x' % id(spam.eggs.SpamAndEggs) '0x8161ce4' '0x%x' % id(SpamAndEggs) '0x814c29c' sag = spam.eggs.SpamAndEggs() isinstance(sag, SpamAndEggs) 0 isinstance(sag, spam.eggs.SpamAndEggs) 1 sag.class <class spam.eggs.SpamAndEggs at 0x8161ce4> sag.class.name 'SpamAndEggs' SpamAndEggs.name 'SpamAndEggs' spam.eggs.SpamAndEggs.name 'SpamAndEggs'
Comment By: Guido van Rossum (gvanrossum) Date: 2001-10-02 12:26
Message: Logged In: YES user_id=6380
We need more information: please show all code involved (use the file upload, please check the checkbox or the upload won't work; you must be logged in to SourceForge as yourself).
From the session you post, it seems that there are two distinct SpamAndEggs objects, but without seeing your code it's hard to understand why.
You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467267&group_id=5470
- Previous message: [Python-bugs-list] [ python-Bugs-467267 ] isinstance depends on import form
- Next message: [Python-bugs-list] [ python-Bugs-467253 ] license points to the wrong file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]