-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[mypyc] Implement list insert primitive #9741
Changes from 2 commits
c7a15d8
1b7105e
8a2e0f0
7d83641
a740332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,15 @@ CPyTagged CPyList_Count(PyObject *obj, PyObject *value) | |
return list_count((PyListObject *)obj, value); | ||
} | ||
|
||
CPyTagged CPyList_Insert(PyObject *list, CPyTagged index, PyObject *value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
{ | ||
if (CPyTagged_CheckShort(index)) { | ||
Py_ssize_t n = CPyTagged_ShortAsSsize_t(index); | ||
return PyList_Insert(list, n, value); | ||
} | ||
return -1; | ||
} | ||
|
||
PyObject *CPyList_Extend(PyObject *o1, PyObject *o2) { | ||
return _PyList_Extend((PyListObject *)o1, o2); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,14 @@ | |
c_function_name='CPyList_Count', | ||
error_kind=ERR_MAGIC) | ||
|
||
# list.insert(index, obj) | ||
method_op( | ||
name='insert', | ||
arg_types=[list_rprimitive, int_rprimitive, object_rprimitive], | ||
return_type=int_rprimitive, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the return type should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that makes sense. Should be ok now. |
||
c_function_name='CPyList_Insert', | ||
error_kind=ERR_MAGIC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
# list * int | ||
binary_op( | ||
name='*', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,12 @@ pop(l, -2) | |
assert l == [1, 3] | ||
assert count(l, 1) == 1 | ||
assert count(l, 2) == 0 | ||
l.insert(0, 0) | ||
assert l == [0, 1, 3] | ||
l.insert(2, 2) | ||
assert l == [0, 1, 2, 3] | ||
l.insert(4, 4) | ||
assert l == [0, 1, 2, 3, 4] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vsakkas This doesn't test the new primitive, since the code is in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course. I'll look into updating the tests in a new PR. |
||
|
||
[case testListOfUserDefinedClass] | ||
class C: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
int
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed