Skip to content

Commit c9149d9

Browse files
authored
fix: Use lowercase builtin collection names (#4833)
1 parent c836059 commit c9149d9

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class tuple_caster {
661661
}
662662

663663
static constexpr auto name
664-
= const_name("Tuple[") + concat(make_caster<Ts>::name...) + const_name("]");
664+
= const_name("tuple[") + concat(make_caster<Ts>::name...) + const_name("]");
665665

666666
template <typename T>
667667
using cast_op_type = type;

include/pybind11/stl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct set_caster {
100100
return s.release();
101101
}
102102

103-
PYBIND11_TYPE_CASTER(type, const_name("Set[") + key_conv::name + const_name("]"));
103+
PYBIND11_TYPE_CASTER(type, const_name("set[") + key_conv::name + const_name("]"));
104104
};
105105

106106
template <typename Type, typename Key, typename Value>
@@ -157,7 +157,7 @@ struct map_caster {
157157
}
158158

159159
PYBIND11_TYPE_CASTER(Type,
160-
const_name("Dict[") + key_conv::name + const_name(", ") + value_conv::name
160+
const_name("dict[") + key_conv::name + const_name(", ") + value_conv::name
161161
+ const_name("]"));
162162
};
163163

@@ -208,7 +208,7 @@ struct list_caster {
208208
return l.release();
209209
}
210210

211-
PYBIND11_TYPE_CASTER(Type, const_name("List[") + value_conv::name + const_name("]"));
211+
PYBIND11_TYPE_CASTER(Type, const_name("list[") + value_conv::name + const_name("]"));
212212
};
213213

214214
template <typename Type, typename Alloc>
@@ -274,7 +274,7 @@ struct array_caster {
274274

275275
PYBIND11_TYPE_CASTER(ArrayType,
276276
const_name<Resizable>(const_name(""), const_name("Annotated["))
277-
+ const_name("List[") + value_conv::name + const_name("]")
277+
+ const_name("list[") + value_conv::name + const_name("]")
278278
+ const_name<Resizable>(const_name(""),
279279
const_name(", FixedSize(")
280280
+ const_name<Size>() + const_name(")]")));

tests/test_builtin_casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ def test_tuple(doc):
352352
assert (
353353
doc(m.pair_passthrough)
354354
== """
355-
pair_passthrough(arg0: Tuple[bool, str]) -> Tuple[str, bool]
355+
pair_passthrough(arg0: tuple[bool, str]) -> tuple[str, bool]
356356
357357
Return a pair in reversed order
358358
"""
359359
)
360360
assert (
361361
doc(m.tuple_passthrough)
362362
== """
363-
tuple_passthrough(arg0: Tuple[bool, str, int]) -> Tuple[int, str, bool]
363+
tuple_passthrough(arg0: tuple[bool, str, int]) -> tuple[int, str, bool]
364364
365365
Return a triple in reversed order
366366
"""

tests/test_kwargs_and_defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_function_signatures(doc):
88
assert doc(m.kw_func1) == "kw_func1(x: int, y: int) -> str"
99
assert doc(m.kw_func2) == "kw_func2(x: int = 100, y: int = 200) -> str"
1010
assert doc(m.kw_func3) == "kw_func3(data: str = 'Hello world!') -> None"
11-
assert doc(m.kw_func4) == "kw_func4(myList: List[int] = [13, 17]) -> str"
11+
assert doc(m.kw_func4) == "kw_func4(myList: list[int] = [13, 17]) -> str"
1212
assert doc(m.kw_func_udl) == "kw_func_udl(x: int, y: int = 300) -> str"
1313
assert doc(m.kw_func_udl_z) == "kw_func_udl_z(x: int, y: int = 0) -> str"
1414
assert doc(m.args_function) == "args_function(*args) -> tuple"

tests/test_stl.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def test_vector(doc):
1616
assert m.load_bool_vector([True, False])
1717
assert m.load_bool_vector((True, False))
1818

19-
assert doc(m.cast_vector) == "cast_vector() -> List[int]"
20-
assert doc(m.load_vector) == "load_vector(arg0: List[int]) -> bool"
19+
assert doc(m.cast_vector) == "cast_vector() -> list[int]"
20+
assert doc(m.load_vector) == "load_vector(arg0: list[int]) -> bool"
2121

2222
# Test regression caused by 936: pointers to stl containers weren't castable
2323
assert m.cast_ptr_vector() == ["lvalue", "lvalue"]
@@ -39,10 +39,10 @@ def test_array(doc):
3939
assert m.load_array(lst)
4040
assert m.load_array(tuple(lst))
4141

42-
assert doc(m.cast_array) == "cast_array() -> Annotated[List[int], FixedSize(2)]"
42+
assert doc(m.cast_array) == "cast_array() -> Annotated[list[int], FixedSize(2)]"
4343
assert (
4444
doc(m.load_array)
45-
== "load_array(arg0: Annotated[List[int], FixedSize(2)]) -> bool"
45+
== "load_array(arg0: Annotated[list[int], FixedSize(2)]) -> bool"
4646
)
4747

4848

@@ -53,8 +53,8 @@ def test_valarray(doc):
5353
assert m.load_valarray(lst)
5454
assert m.load_valarray(tuple(lst))
5555

56-
assert doc(m.cast_valarray) == "cast_valarray() -> List[int]"
57-
assert doc(m.load_valarray) == "load_valarray(arg0: List[int]) -> bool"
56+
assert doc(m.cast_valarray) == "cast_valarray() -> list[int]"
57+
assert doc(m.load_valarray) == "load_valarray(arg0: list[int]) -> bool"
5858

5959

6060
def test_map(doc):
@@ -66,8 +66,8 @@ def test_map(doc):
6666
assert "key2" in d
6767
assert m.load_map(d)
6868

69-
assert doc(m.cast_map) == "cast_map() -> Dict[str, str]"
70-
assert doc(m.load_map) == "load_map(arg0: Dict[str, str]) -> bool"
69+
assert doc(m.cast_map) == "cast_map() -> dict[str, str]"
70+
assert doc(m.load_map) == "load_map(arg0: dict[str, str]) -> bool"
7171

7272

7373
def test_set(doc):
@@ -78,8 +78,8 @@ def test_set(doc):
7878
assert m.load_set(s)
7979
assert m.load_set(frozenset(s))
8080

81-
assert doc(m.cast_set) == "cast_set() -> Set[str]"
82-
assert doc(m.load_set) == "load_set(arg0: Set[str]) -> bool"
81+
assert doc(m.cast_set) == "cast_set() -> set[str]"
82+
assert doc(m.load_set) == "load_set(arg0: set[str]) -> bool"
8383

8484

8585
def test_recursive_casting():
@@ -303,7 +303,7 @@ def test_stl_pass_by_pointer(msg):
303303
msg(excinfo.value)
304304
== """
305305
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
306-
1. (v: List[int] = None) -> List[int]
306+
1. (v: list[int] = None) -> list[int]
307307
308308
Invoked with:
309309
"""
@@ -315,7 +315,7 @@ def test_stl_pass_by_pointer(msg):
315315
msg(excinfo.value)
316316
== """
317317
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
318-
1. (v: List[int] = None) -> List[int]
318+
1. (v: list[int] = None) -> list[int]
319319
320320
Invoked with: None
321321
"""

0 commit comments

Comments
 (0)