Files
pybind11/tests/test_docs_advanced_cast_custom.py
gentlegiantJGC 67424358f4 fix(types): add typing and collections.abc module prefix (#5663)
* Fix Python 3.8 type hints and add module prefix

These type hints are invalid in Python 3.8.
Add `typing.` prefix to remove ambiguity.

* style: pre-commit fixes

* Add module prefix to Union

* Rename macros

* Improve comment

* Comment out 3.8 type hint macros

Fixing this issue in Python 3.8 will require updating lots of tests. This can be added in a further pull request.

* Add Iterable module prefix

* Add module prefix to Iterator

* Add module prefix to Callable

* Re-add accidentally deleted brackets

* Add module prefix to Optional

* Add module prefix to Final

* Add module prefix to ClassVar

* Add module prefix to TypeGuard

* Add module prefix to TypeIs

* Add module prefix to NoReturn

* Add module prefix to Never

* Add module prefix to Literal

* Add module prefix to Callable

* Add module prefix to Sequence

* Add module prefix to Iterator

* style: pre-commit fixes

* Remove type hint macros

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-05-19 11:54:31 -04:00

41 lines
1.2 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING, Sequence
if TYPE_CHECKING:
from conftest import SanitizedString
from pybind11_tests import docs_advanced_cast_custom as m
def assert_negate_function(
input_sequence: Sequence[float],
target: tuple[float, float],
) -> None:
output = m.negate(input_sequence)
assert isinstance(output, tuple)
assert len(output) == 2
assert isinstance(output[0], float)
assert isinstance(output[1], float)
assert output == target
def test_negate(doc: SanitizedString) -> None:
assert (
doc(m.negate)
== "negate(arg0: collections.abc.Sequence[float]) -> tuple[float, float]"
)
assert_negate_function([1.0, -1.0], (-1.0, 1.0))
assert_negate_function((1.0, -1.0), (-1.0, 1.0))
assert_negate_function([1, -1], (-1.0, 1.0))
assert_negate_function((1, -1), (-1.0, 1.0))
def test_docs() -> None:
###########################################################################
# PLEASE UPDATE docs/advanced/cast/custom.rst IF ANY CHANGES ARE MADE HERE.
###########################################################################
point1 = [1.0, -1.0]
point2 = m.negate(point1)
assert point2 == (-1.0, 1.0)