mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
feat(types): Use typing.SupportsInt and typing.SupportsFloat and fix other typing based bugs. (#5540)
* init Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * remove import Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * remove uneeded function Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes * Add missing import Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes * Fix type behind detailed_message_enabled flag Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Fix type behind detailed_message_enabled flag Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Add io_name comment Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Extra loops to single function Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes * Remove unneeded forward declaration Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Switch variable name away from macro Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Switch variable name away from macro Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * Switch variable name away from macro Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * clang-tidy Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * remove stack import * Fix bug in std::function Callable type Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes * remove is_annotation argument Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes * Update function name and arg names Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> * style: pre-commit fixes --------- Signed-off-by: Michael Carlstrom <rmc@carlstrom.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
16b5abd428
commit
dfe7e65b45
@@ -20,7 +20,7 @@ def test_vector(doc):
|
||||
assert m.load_bool_vector((True, False))
|
||||
|
||||
assert doc(m.cast_vector) == "cast_vector() -> list[int]"
|
||||
assert doc(m.load_vector) == "load_vector(arg0: list[int]) -> bool"
|
||||
assert doc(m.load_vector) == "load_vector(arg0: list[typing.SupportsInt]) -> bool"
|
||||
|
||||
# Test regression caused by 936: pointers to stl containers weren't castable
|
||||
assert m.cast_ptr_vector() == ["lvalue", "lvalue"]
|
||||
@@ -45,7 +45,7 @@ def test_array(doc):
|
||||
assert doc(m.cast_array) == "cast_array() -> Annotated[list[int], FixedSize(2)]"
|
||||
assert (
|
||||
doc(m.load_array)
|
||||
== "load_array(arg0: Annotated[list[int], FixedSize(2)]) -> bool"
|
||||
== "load_array(arg0: Annotated[list[typing.SupportsInt], FixedSize(2)]) -> bool"
|
||||
)
|
||||
|
||||
|
||||
@@ -64,7 +64,9 @@ def test_valarray(doc):
|
||||
assert m.load_valarray(tuple(lst))
|
||||
|
||||
assert doc(m.cast_valarray) == "cast_valarray() -> list[int]"
|
||||
assert doc(m.load_valarray) == "load_valarray(arg0: list[int]) -> bool"
|
||||
assert (
|
||||
doc(m.load_valarray) == "load_valarray(arg0: list[typing.SupportsInt]) -> bool"
|
||||
)
|
||||
|
||||
|
||||
def test_map(doc):
|
||||
@@ -325,7 +327,8 @@ def test_variant(doc):
|
||||
assert m.cast_variant() == (5, "Hello")
|
||||
|
||||
assert (
|
||||
doc(m.load_variant) == "load_variant(arg0: Union[int, str, float, None]) -> str"
|
||||
doc(m.load_variant)
|
||||
== "load_variant(arg0: Union[typing.SupportsInt, str, typing.SupportsFloat, None]) -> str"
|
||||
)
|
||||
|
||||
|
||||
@@ -341,7 +344,7 @@ def test_variant_monostate(doc):
|
||||
|
||||
assert (
|
||||
doc(m.load_monostate_variant)
|
||||
== "load_monostate_variant(arg0: Union[None, int, str]) -> str"
|
||||
== "load_monostate_variant(arg0: Union[None, typing.SupportsInt, str]) -> str"
|
||||
)
|
||||
|
||||
|
||||
@@ -361,7 +364,7 @@ def test_stl_pass_by_pointer(msg):
|
||||
msg(excinfo.value)
|
||||
== """
|
||||
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
|
||||
1. (v: list[int] = None) -> list[int]
|
||||
1. (v: list[typing.SupportsInt] = None) -> list[int]
|
||||
|
||||
Invoked with:
|
||||
"""
|
||||
@@ -373,7 +376,7 @@ def test_stl_pass_by_pointer(msg):
|
||||
msg(excinfo.value)
|
||||
== """
|
||||
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
|
||||
1. (v: list[int] = None) -> list[int]
|
||||
1. (v: list[typing.SupportsInt] = None) -> list[int]
|
||||
|
||||
Invoked with: None
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user