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
65370f33
Unverified
Commit
65370f33
authored
Mar 21, 2024
by
Jason Watson
Committed by
GitHub
Mar 21, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create handle_type_name specialization to type-hint variable length tuples (#5051)
parent
ddb8b67a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
0 deletions
+16
-0
include/pybind11/typing.h
+7
-0
tests/test_pytypes.cpp
+2
-0
tests/test_pytypes.py
+7
-0
No files found.
include/pybind11/typing.h
View file @
65370f33
...
...
@@ -79,6 +79,13 @@ struct handle_type_name<typing::Tuple<>> {
static
constexpr
auto
name
=
const_name
(
"tuple[()]"
);
};
template
<
typename
T
>
struct
handle_type_name
<
typing
::
Tuple
<
T
,
ellipsis
>>
{
// PEP 484 specifies this syntax for a variable-length tuple
static
constexpr
auto
name
=
const_name
(
"tuple["
)
+
make_caster
<
T
>::
name
+
const_name
(
", ...]"
);
};
template
<
typename
K
,
typename
V
>
struct
handle_type_name
<
typing
::
Dict
<
K
,
V
>>
{
static
constexpr
auto
name
=
const_name
(
"dict["
)
+
make_caster
<
K
>::
name
+
const_name
(
", "
)
...
...
tests/test_pytypes.cpp
View file @
65370f33
...
...
@@ -825,6 +825,8 @@ TEST_SUBMODULE(pytypes, m) {
m
.
def
(
"annotate_tuple_float_str"
,
[](
const
py
::
typing
::
Tuple
<
py
::
float_
,
py
::
str
>
&
)
{});
m
.
def
(
"annotate_tuple_empty"
,
[](
const
py
::
typing
::
Tuple
<>
&
)
{});
m
.
def
(
"annotate_tuple_variable_length"
,
[](
const
py
::
typing
::
Tuple
<
py
::
float_
,
py
::
ellipsis
>
&
)
{});
m
.
def
(
"annotate_dict_str_int"
,
[](
const
py
::
typing
::
Dict
<
py
::
str
,
int
>
&
)
{});
m
.
def
(
"annotate_list_int"
,
[](
const
py
::
typing
::
List
<
int
>
&
)
{});
m
.
def
(
"annotate_set_str"
,
[](
const
py
::
typing
::
Set
<
std
::
string
>
&
)
{});
...
...
tests/test_pytypes.py
View file @
65370f33
...
...
@@ -911,6 +911,13 @@ def test_tuple_empty_annotations(doc):
)
def
test_tuple_variable_length_annotations
(
doc
):
assert
(
doc
(
m
.
annotate_tuple_variable_length
)
==
"annotate_tuple_variable_length(arg0: tuple[float, ...]) -> None"
)
def
test_dict_annotations
(
doc
):
assert
(
doc
(
m
.
annotate_dict_str_int
)
...
...
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