Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
12e8774b
Commit
12e8774b
authored
Aug 19, 2019
by
kingofpayne
Committed by
Wenzel Jakob
Aug 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for list insertion. (#1888)
parent
19189b4c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
3 deletions
+11
-3
include/pybind11/pytypes.h
+4
-0
tests/test_pytypes.cpp
+2
-0
tests/test_pytypes.py
+5
-3
No files found.
include/pybind11/pytypes.h
View file @
12e8774b
...
@@ -1265,6 +1265,10 @@ public:
...
@@ -1265,6 +1265,10 @@ public:
template
<
typename
T
>
void
append
(
T
&&
val
)
const
{
template
<
typename
T
>
void
append
(
T
&&
val
)
const
{
PyList_Append
(
m_ptr
,
detail
::
object_or_cast
(
std
::
forward
<
T
>
(
val
)).
ptr
());
PyList_Append
(
m_ptr
,
detail
::
object_or_cast
(
std
::
forward
<
T
>
(
val
)).
ptr
());
}
}
template
<
typename
T
>
void
insert
(
size_t
index
,
T
&&
val
)
const
{
PyList_Insert
(
m_ptr
,
static_cast
<
ssize_t
>
(
index
),
detail
::
object_or_cast
(
std
::
forward
<
T
>
(
val
)).
ptr
());
}
};
};
class
args
:
public
tuple
{
PYBIND11_OBJECT_DEFAULT
(
args
,
tuple
,
PyTuple_Check
)
};
class
args
:
public
tuple
{
PYBIND11_OBJECT_DEFAULT
(
args
,
tuple
,
PyTuple_Check
)
};
...
...
tests/test_pytypes.cpp
View file @
12e8774b
...
@@ -17,6 +17,8 @@ TEST_SUBMODULE(pytypes, m) {
...
@@ -17,6 +17,8 @@ TEST_SUBMODULE(pytypes, m) {
list
.
append
(
"value"
);
list
.
append
(
"value"
);
py
::
print
(
"Entry at position 0:"
,
list
[
0
]);
py
::
print
(
"Entry at position 0:"
,
list
[
0
]);
list
[
0
]
=
py
::
str
(
"overwritten"
);
list
[
0
]
=
py
::
str
(
"overwritten"
);
list
.
insert
(
0
,
"inserted-0"
);
list
.
insert
(
2
,
"inserted-2"
);
return
list
;
return
list
;
});
});
m
.
def
(
"print_list"
,
[](
py
::
list
list
)
{
m
.
def
(
"print_list"
,
[](
py
::
list
list
)
{
...
...
tests/test_pytypes.py
View file @
12e8774b
...
@@ -9,14 +9,16 @@ from pybind11_tests import debug_enabled
...
@@ -9,14 +9,16 @@ from pybind11_tests import debug_enabled
def
test_list
(
capture
,
doc
):
def
test_list
(
capture
,
doc
):
with
capture
:
with
capture
:
lst
=
m
.
get_list
()
lst
=
m
.
get_list
()
assert
lst
==
[
"
overwritten
"
]
assert
lst
==
[
"
inserted-0"
,
"overwritten"
,
"inserted-2
"
]
lst
.
append
(
"value2"
)
lst
.
append
(
"value2"
)
m
.
print_list
(
lst
)
m
.
print_list
(
lst
)
assert
capture
.
unordered
==
"""
assert
capture
.
unordered
==
"""
Entry at position 0: value
Entry at position 0: value
list item 0: overwritten
list item 0: inserted-0
list item 1: value2
list item 1: overwritten
list item 2: inserted-2
list item 3: value2
"""
"""
assert
doc
(
m
.
get_list
)
==
"get_list() -> list"
assert
doc
(
m
.
get_list
)
==
"get_list() -> list"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment