[Python-Dev] PyInstance_Check() and new-style classes (original) (raw)
Phillip J. Eby pje at telecommunity.com
Mon Jul 12 15:48:19 CEST 2004
- Previous message: [Python-Dev] PyInstance_Check() and new-style classes
- Next message: [Python-Dev] PyInstance_Check() and new-style classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 08:11 PM 7/11/04 -0500, Eric Wilhelm wrote:
So, is PyInstanceCheck() supposed to work, or is there some PyFooCheck() function that will work?
No, to both questions.
It seems really wrong to have to add-up all of the other types and use this process of elimination to identify a new-style class instance.
As of 2.2, all Python types except InstanceType may be considered to be "new-style class instances".
If you want to find out whether a type was defined in Python or C, you can use the "heap type" flag in the type structure. Note, however, that this will not let you distinguish between core C types and C extension types, so using it might be a bad idea if the reason you're using Python is to use a Python module written in C!
Also, it seems that it would fail if a class inherited from a built-in type. I'm almost sure that I'm way off-course, so if anyone could put me on track, I'd really appreciate it.
Why do you want to distinguish between different kinds of objects? Is it because Perl needs/wants Python strings and numbers to become scalars? Perhaps you should simply convert those types that you want an exact conversion for, and consider everything else to be "instances". Better yet, provide a way for the user to define Perl mappings for specific Python types, which would give more flexibility in bridging the two, or require explicit conversion operations. Or perhaps you could use Perl contexts in some way to decide what type of conversion should take place?
(Also, isn't there a Python::Object package out there? What does it do? Has it been updated for Python 2.2?)
- Previous message: [Python-Dev] PyInstance_Check() and new-style classes
- Next message: [Python-Dev] PyInstance_Check() and new-style classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]