Skip to content

Commit cb0da62

Browse files
Use Pybind11 3.0.0+ (#20095)
Pybind11 had a new major version bump to [3.0.0](https://github.com/pybind/pybind11/releases/tag/v3.0.0). Also fix bug in workflow to run with the new folder name. Signed-off-by: Michael Carlstrom <[email protected]>
1 parent b266dd1 commit cb0da62

File tree

6 files changed

+63
-59
lines changed

6 files changed

+63
-59
lines changed

.github/workflows/test_stubgenc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- 'mypy/stubgenc.py'
1212
- 'mypy/stubdoc.py'
1313
- 'mypy/stubutil.py'
14-
- 'test-data/stubgen/**'
14+
- 'test-data/pybind11_fixtures/**'
1515

1616
permissions:
1717
contents: read
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import os
1+
import pathlib
2+
import typing
23
from . import demo as demo
34
from typing import overload
45

56
class StaticMethods:
67
def __init__(self, *args, **kwargs) -> None: ...
78
@overload
89
@staticmethod
9-
def overloaded_static_method(value: int) -> int: ...
10+
def overloaded_static_method(value: typing.SupportsInt) -> int: ...
1011
@overload
1112
@staticmethod
12-
def overloaded_static_method(value: float) -> float: ...
13+
def overloaded_static_method(value: typing.SupportsFloat) -> float: ...
1314
@staticmethod
14-
def some_static_method(a: int, b: int) -> int: ...
15+
def some_static_method(a: typing.SupportsInt, b: typing.SupportsInt) -> int: ...
1516

1617
class TestStruct:
1718
field_readwrite: int
@@ -23,5 +24,5 @@ class TestStruct:
2324
def func_incomplete_signature(*args, **kwargs): ...
2425
def func_returning_optional() -> int | None: ...
2526
def func_returning_pair() -> tuple[int, float]: ...
26-
def func_returning_path() -> os.PathLike: ...
27+
def func_returning_path() -> pathlib.Path: ...
2728
def func_returning_vector() -> list[float]: ...

test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/demo.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
from typing import ClassVar, overload
23

34
PI: float
@@ -9,7 +10,7 @@ class Point:
910
__entries: ClassVar[dict] = ...
1011
degree: ClassVar[Point.AngleUnit] = ...
1112
radian: ClassVar[Point.AngleUnit] = ...
12-
def __init__(self, value: int) -> None: ...
13+
def __init__(self, value: typing.SupportsInt) -> None: ...
1314
def __eq__(self, other: object) -> bool: ...
1415
def __hash__(self) -> int: ...
1516
def __index__(self) -> int: ...
@@ -26,7 +27,7 @@ class Point:
2627
inch: ClassVar[Point.LengthUnit] = ...
2728
mm: ClassVar[Point.LengthUnit] = ...
2829
pixel: ClassVar[Point.LengthUnit] = ...
29-
def __init__(self, value: int) -> None: ...
30+
def __init__(self, value: typing.SupportsInt) -> None: ...
3031
def __eq__(self, other: object) -> bool: ...
3132
def __hash__(self) -> int: ...
3233
def __index__(self) -> int: ...
@@ -46,16 +47,16 @@ class Point:
4647
@overload
4748
def __init__(self) -> None: ...
4849
@overload
49-
def __init__(self, x: float, y: float) -> None: ...
50+
def __init__(self, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None: ...
5051
def as_list(self) -> list[float]: ...
5152
@overload
52-
def distance_to(self, x: float, y: float) -> float: ...
53+
def distance_to(self, x: typing.SupportsFloat, y: typing.SupportsFloat) -> float: ...
5354
@overload
5455
def distance_to(self, other: Point) -> float: ...
5556
@property
5657
def length(self) -> float: ...
5758

5859
def answer() -> int: ...
59-
def midpoint(left: float, right: float) -> float: ...
60-
def sum(arg0: int, arg1: int) -> int: ...
61-
def weighted_midpoint(left: float, right: float, alpha: float = ...) -> float: ...
60+
def midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat) -> float: ...
61+
def sum(arg0: typing.SupportsInt, arg1: typing.SupportsInt) -> int: ...
62+
def weighted_midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat, alpha: typing.SupportsFloat = ...) -> float: ...
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os
1+
import pathlib
2+
import typing
23
from . import demo as demo
34
from typing import overload
45

@@ -7,27 +8,27 @@ class StaticMethods:
78
"""Initialize self. See help(type(self)) for accurate signature."""
89
@overload
910
@staticmethod
10-
def overloaded_static_method(value: int) -> int:
11+
def overloaded_static_method(value: typing.SupportsInt) -> int:
1112
"""overloaded_static_method(*args, **kwargs)
1213
Overloaded function.
1314
14-
1. overloaded_static_method(value: int) -> int
15+
1. overloaded_static_method(value: typing.SupportsInt) -> int
1516
16-
2. overloaded_static_method(value: float) -> float
17+
2. overloaded_static_method(value: typing.SupportsFloat) -> float
1718
"""
1819
@overload
1920
@staticmethod
20-
def overloaded_static_method(value: float) -> float:
21+
def overloaded_static_method(value: typing.SupportsFloat) -> float:
2122
"""overloaded_static_method(*args, **kwargs)
2223
Overloaded function.
2324
24-
1. overloaded_static_method(value: int) -> int
25+
1. overloaded_static_method(value: typing.SupportsInt) -> int
2526
26-
2. overloaded_static_method(value: float) -> float
27+
2. overloaded_static_method(value: typing.SupportsFloat) -> float
2728
"""
2829
@staticmethod
29-
def some_static_method(a: int, b: int) -> int:
30-
"""some_static_method(a: int, b: int) -> int
30+
def some_static_method(a: typing.SupportsInt, b: typing.SupportsInt) -> int:
31+
"""some_static_method(a: typing.SupportsInt, b: typing.SupportsInt) -> int
3132
3233
None
3334
"""
@@ -46,10 +47,10 @@ class TestStruct:
4647
def func_incomplete_signature(*args, **kwargs):
4748
"""func_incomplete_signature() -> dummy_sub_namespace::HasNoBinding"""
4849
def func_returning_optional() -> int | None:
49-
"""func_returning_optional() -> Optional[int]"""
50+
"""func_returning_optional() -> int | None"""
5051
def func_returning_pair() -> tuple[int, float]:
51-
"""func_returning_pair() -> Tuple[int, float]"""
52-
def func_returning_path() -> os.PathLike:
53-
"""func_returning_path() -> os.PathLike"""
52+
"""func_returning_pair() -> tuple[int, float]"""
53+
def func_returning_path() -> pathlib.Path:
54+
"""func_returning_path() -> pathlib.Path"""
5455
def func_returning_vector() -> list[float]:
55-
"""func_returning_vector() -> List[float]"""
56+
"""func_returning_vector() -> list[float]"""

test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/demo.pyi

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
from typing import ClassVar, overload
23

34
PI: float
@@ -14,23 +15,23 @@ class Point:
1415
__entries: ClassVar[dict] = ...
1516
degree: ClassVar[Point.AngleUnit] = ...
1617
radian: ClassVar[Point.AngleUnit] = ...
17-
def __init__(self, value: int) -> None:
18-
"""__init__(self: pybind11_fixtures.demo.Point.AngleUnit, value: int) -> None"""
18+
def __init__(self, value: typing.SupportsInt) -> None:
19+
"""__init__(self: pybind11_fixtures.demo.Point.AngleUnit, value: typing.SupportsInt) -> None"""
1920
def __eq__(self, other: object) -> bool:
20-
"""__eq__(self: object, other: object) -> bool"""
21+
"""__eq__(self: object, other: object, /) -> bool"""
2122
def __hash__(self) -> int:
22-
"""__hash__(self: object) -> int"""
23+
"""__hash__(self: object, /) -> int"""
2324
def __index__(self) -> int:
24-
"""__index__(self: pybind11_fixtures.demo.Point.AngleUnit) -> int"""
25+
"""__index__(self: pybind11_fixtures.demo.Point.AngleUnit, /) -> int"""
2526
def __int__(self) -> int:
26-
"""__int__(self: pybind11_fixtures.demo.Point.AngleUnit) -> int"""
27+
"""__int__(self: pybind11_fixtures.demo.Point.AngleUnit, /) -> int"""
2728
def __ne__(self, other: object) -> bool:
28-
"""__ne__(self: object, other: object) -> bool"""
29+
"""__ne__(self: object, other: object, /) -> bool"""
2930
@property
3031
def name(self) -> str:
31-
"""name(self: handle) -> str
32+
"""name(self: object, /) -> str
3233
33-
name(self: handle) -> str
34+
name(self: object, /) -> str
3435
"""
3536
@property
3637
def value(self) -> int:
@@ -49,23 +50,23 @@ class Point:
4950
inch: ClassVar[Point.LengthUnit] = ...
5051
mm: ClassVar[Point.LengthUnit] = ...
5152
pixel: ClassVar[Point.LengthUnit] = ...
52-
def __init__(self, value: int) -> None:
53-
"""__init__(self: pybind11_fixtures.demo.Point.LengthUnit, value: int) -> None"""
53+
def __init__(self, value: typing.SupportsInt) -> None:
54+
"""__init__(self: pybind11_fixtures.demo.Point.LengthUnit, value: typing.SupportsInt) -> None"""
5455
def __eq__(self, other: object) -> bool:
55-
"""__eq__(self: object, other: object) -> bool"""
56+
"""__eq__(self: object, other: object, /) -> bool"""
5657
def __hash__(self) -> int:
57-
"""__hash__(self: object) -> int"""
58+
"""__hash__(self: object, /) -> int"""
5859
def __index__(self) -> int:
59-
"""__index__(self: pybind11_fixtures.demo.Point.LengthUnit) -> int"""
60+
"""__index__(self: pybind11_fixtures.demo.Point.LengthUnit, /) -> int"""
6061
def __int__(self) -> int:
61-
"""__int__(self: pybind11_fixtures.demo.Point.LengthUnit) -> int"""
62+
"""__int__(self: pybind11_fixtures.demo.Point.LengthUnit, /) -> int"""
6263
def __ne__(self, other: object) -> bool:
63-
"""__ne__(self: object, other: object) -> bool"""
64+
"""__ne__(self: object, other: object, /) -> bool"""
6465
@property
6566
def name(self) -> str:
66-
"""name(self: handle) -> str
67+
"""name(self: object, /) -> str
6768
68-
name(self: handle) -> str
69+
name(self: object, /) -> str
6970
"""
7071
@property
7172
def value(self) -> int:
@@ -84,25 +85,25 @@ class Point:
8485
8586
1. __init__(self: pybind11_fixtures.demo.Point) -> None
8687
87-
2. __init__(self: pybind11_fixtures.demo.Point, x: float, y: float) -> None
88+
2. __init__(self: pybind11_fixtures.demo.Point, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None
8889
"""
8990
@overload
90-
def __init__(self, x: float, y: float) -> None:
91+
def __init__(self, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None:
9192
"""__init__(*args, **kwargs)
9293
Overloaded function.
9394
9495
1. __init__(self: pybind11_fixtures.demo.Point) -> None
9596
96-
2. __init__(self: pybind11_fixtures.demo.Point, x: float, y: float) -> None
97+
2. __init__(self: pybind11_fixtures.demo.Point, x: typing.SupportsFloat, y: typing.SupportsFloat) -> None
9798
"""
9899
def as_list(self) -> list[float]:
99-
"""as_list(self: pybind11_fixtures.demo.Point) -> List[float]"""
100+
"""as_list(self: pybind11_fixtures.demo.Point) -> list[float]"""
100101
@overload
101-
def distance_to(self, x: float, y: float) -> float:
102+
def distance_to(self, x: typing.SupportsFloat, y: typing.SupportsFloat) -> float:
102103
"""distance_to(*args, **kwargs)
103104
Overloaded function.
104105
105-
1. distance_to(self: pybind11_fixtures.demo.Point, x: float, y: float) -> float
106+
1. distance_to(self: pybind11_fixtures.demo.Point, x: typing.SupportsFloat, y: typing.SupportsFloat) -> float
106107
107108
2. distance_to(self: pybind11_fixtures.demo.Point, other: pybind11_fixtures.demo.Point) -> float
108109
"""
@@ -111,7 +112,7 @@ class Point:
111112
"""distance_to(*args, **kwargs)
112113
Overloaded function.
113114
114-
1. distance_to(self: pybind11_fixtures.demo.Point, x: float, y: float) -> float
115+
1. distance_to(self: pybind11_fixtures.demo.Point, x: typing.SupportsFloat, y: typing.SupportsFloat) -> float
115116
116117
2. distance_to(self: pybind11_fixtures.demo.Point, other: pybind11_fixtures.demo.Point) -> float
117118
"""
@@ -124,12 +125,12 @@ def answer() -> int:
124125
125126
answer docstring, with end quote"
126127
'''
127-
def midpoint(left: float, right: float) -> float:
128-
"""midpoint(left: float, right: float) -> float"""
129-
def sum(arg0: int, arg1: int) -> int:
130-
'''sum(arg0: int, arg1: int) -> int
128+
def midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat) -> float:
129+
"""midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat) -> float"""
130+
def sum(arg0: typing.SupportsInt, arg1: typing.SupportsInt) -> int:
131+
'''sum(arg0: typing.SupportsInt, arg1: typing.SupportsInt) -> int
131132
132133
multiline docstring test, edge case quotes """\'\'\'
133134
'''
134-
def weighted_midpoint(left: float, right: float, alpha: float = ...) -> float:
135-
"""weighted_midpoint(left: float, right: float, alpha: float = 0.5) -> float"""
135+
def weighted_midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat, alpha: typing.SupportsFloat = ...) -> float:
136+
"""weighted_midpoint(left: typing.SupportsFloat, right: typing.SupportsFloat, alpha: typing.SupportsFloat = 0.5) -> float"""

test-data/pybind11_fixtures/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [
44
"wheel",
55
# Officially supported pybind11 version. This is pinned to guarantee 100% reproducible CI.
66
# As a result, the version needs to be bumped manually at will.
7-
"pybind11==2.9.2",
7+
"pybind11==3.0.1",
88
]
99

1010
build-backend = "setuptools.build_meta"

0 commit comments

Comments
 (0)