Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyObject_IsInstance() doesn't find bases named in type(name, bases, dict) #47164

Closed
scoder opened this issue May 19, 2008 · 2 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@scoder
Copy link
Contributor

scoder commented May 19, 2008

BPO 2915
Nosy @scoder

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-05-21.20:44:48.094>
created_at = <Date 2008-05-19.15:44:50.315>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = "PyObject_IsInstance() doesn't find bases named in type(name, bases, dict)"
updated_at = <Date 2008-05-21.20:44:48.093>
user = 'https://github.com/scoder'

bugs.python.org fields:

activity = <Date 2008-05-21.20:44:48.093>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2008-05-21.20:44:48.094>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2008-05-19.15:44:50.315>
creator = 'scoder'
dependencies = []
files = []
hgrepos = []
issue_num = 2915
keywords = []
message_count = 2.0
messages = ['67065', '67171']
nosy_count = 1.0
nosy_names = ['scoder']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2915'
versions = ['Python 3.0']

@scoder
Copy link
Contributor Author

scoder commented May 19, 2008

While porting the code that Cython generates to Py3a5 (almost completed,
BTW), I noticed a problem with class creation. We are currently using
this call to create a new class in Py3:

PyObject_CallFunctionObjArgs((PyObject *)&PyType_Type,
                             name, bases, dict, NULL);

As an example, I subtype the built-in "list" type like this (Cython code!):

    class B(list):
        def append(self, *args):
            for arg in args:
                list.append(self, arg)

which calls type() as shown above with name="B" and bases=(PyList_Type,).

Surprisingly to me, the call to .append() then fails in the method
descriptor code with a type error on "self". I tried calling super(...)
instead, and it gives a similar error. I read through the descriptor
code and the thing that fails here is

PyObject_IsInstance(self, (PyObject \*)(descr-\>d_type))

in line 229 of descrobject.c, which internally calls

    PyObject_TypeCheck(inst, (PyTypeObject *)cls)

in line 2543 of abstract.c. The problem here is that this checks the
ob_type, which holds a "type" and not a "B", so it doesn't find the base
type "list" of the "B" type and instead looks through the base types of
"type". The result is that PyObject_IsInstance() does not consider the
result of the above call to type(name, bases, dict) an instance of the
types that were named in "bases".

As this works in Python 2.5.1 and also for equivalent Python code in the
interpreter of Python 3.0a5, I assume that this is a bug in the alpha
version.

@scoder scoder added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels May 19, 2008
@scoder
Copy link
Contributor Author

scoder commented May 21, 2008

Sorry, the bug was in Cython, which didn't call InstanceMethod().

Please ignore.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants