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
26281c79
Unverified
Commit
26281c79
authored
Jun 25, 2024
by
Michael Carlstrom
Committed by
GitHub
Jun 25, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(types): adds support for Never and NoReturn from python Typing (#5193)
* Adds support for Never and NoReturn * lint
parent
183059f9
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
include/pybind11/typing.h
+16
-0
tests/test_pytypes.cpp
+3
-0
tests/test_pytypes.py
+8
-0
No files found.
include/pybind11/typing.h
View file @
26281c79
...
...
@@ -80,6 +80,13 @@ class Optional : public object {
using
object
::
object
;
};
class
NoReturn
:
public
none
{
using
none
::
none
;
};
class
Never
:
public
none
{
using
none
::
none
;
};
#if defined(__cpp_nontype_template_parameter_class)
template
<
size_t
N
>
struct
StringLiteral
{
...
...
@@ -176,6 +183,15 @@ struct handle_type_name<typing::Optional<T>> {
static
constexpr
auto
name
=
const_name
(
"Optional["
)
+
make_caster
<
T
>::
name
+
const_name
(
"]"
);
};
template
<>
struct
handle_type_name
<
typing
::
NoReturn
>
{
static
constexpr
auto
name
=
const_name
(
"NoReturn"
);
};
template
<>
struct
handle_type_name
<
typing
::
Never
>
{
static
constexpr
auto
name
=
const_name
(
"Never"
);
};
#if defined(__cpp_nontype_template_parameter_class)
template
<
typing
::
StringLiteral
...
Literals
>
struct
handle_type_name
<
typing
::
Literal
<
Literals
...
>>
{
...
...
tests/test_pytypes.cpp
View file @
26281c79
...
...
@@ -891,6 +891,9 @@ TEST_SUBMODULE(pytypes, m) {
list
.
append
(
py
::
none
());
return
list
;
});
m
.
def
(
"annotate_no_return"
,
[]()
->
py
::
typing
::
NoReturn
{
throw
0
;
});
m
.
def
(
"annotate_never"
,
[]()
->
py
::
typing
::
Never
{
throw
0
;
});
m
.
def
(
"annotate_optional_to_object"
,
[](
py
::
typing
::
Optional
<
int
>
&
o
)
->
py
::
object
{
return
o
;
});
...
...
tests/test_pytypes.py
View file @
26281c79
...
...
@@ -991,6 +991,14 @@ def test_optional_annotations(doc):
)
def
test_no_return_annotation
(
doc
):
assert
doc
(
m
.
annotate_no_return
)
==
"annotate_no_return() -> NoReturn"
def
test_never_annotation
(
doc
):
assert
doc
(
m
.
annotate_never
)
==
"annotate_never() -> Never"
def
test_optional_object_annotations
(
doc
):
assert
(
doc
(
m
.
annotate_optional_to_object
)
...
...
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