Skip to content

Add tests for using PEP560 with classes implemented in C.#4883

Merged
ilevkivskyi merged 3 commits into
python:masterfrom
serhiy-storchaka:pep560-test-capi
Dec 16, 2017
Merged

Add tests for using PEP560 with classes implemented in C.#4883
ilevkivskyi merged 3 commits into
python:masterfrom
serhiy-storchaka:pep560-test-capi

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Based on tests from #4878.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LG.

Comment thread Modules/_testcapimodule.c Outdated
return -1;
}

o->item = item;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a DECREF missing here? PyArg_UnpackTuple returns a borrowed item. Also there might be a value already here so a DECREF would also be needed (before the assignment). Unless I misunderstand something (totally possible, I feel very rusty in this area :-).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Py_INCREF(item) is needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for the purposes of this test we should be able to just remove this function and tp_init slot.

Comment thread Modules/_testcapimodule.c Outdated
} PyGenericObject;


/* Test PEP 560 slots */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated comment

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding these tests! I just have one suggestion to make the test closer to how these methods will be used in typical code. The idea is that there will be typically a pair of classes:

class Generic:
    def __class_getitem__(cls, item):
        return GenericAlias(item)

class GenericAlias:
    def __init__(self, item):
        self.item = item
    def __mro_entries__(self, bases):
        return (item,)

but this is just a minor suggestion, you can merge it as is if you prefer.

@ilevkivskyi

Copy link
Copy Markdown
Member

Thanks!

(If we agree to change __class_getitem__ to classmethod, then I will update this test later.)

@ilevkivskyi ilevkivskyi merged commit 45700fb into python:master Dec 16, 2017
@serhiy-storchaka serhiy-storchaka deleted the pep560-test-capi branch December 21, 2017 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip issue skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants