Skip to content

Commit

Permalink
Added commented failing tests for Literals with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
timohl committed Jan 5, 2025
1 parent a86e7c4 commit 9877aca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,11 @@ TEST_SUBMODULE(pytypes, m) {
m.def("check_type_is", [](const py::object &x) -> py::typing::TypeIs<RealNumber> {
return py::isinstance<RealNumber>(x);
});
// Literal with `@`, `%`, `{`, and `}`
// m.def("identity_literal_x", [](const py::typing::Literal<"\"x\""> &x) { return x; });
// m.def("identity_literal_at", [](const py::typing::Literal<"\"@\""> &x) { return x; });
// m.def("identity_literal_percent", [](const py::typing::Literal<"\"%\""> &x) { return x; });
// m.def("identity_literal_curly_open", [](const py::typing::Literal<"\"{\""> &x) { return x;
// }); m.def("identity_literal_curly_close", [](const py::typing::Literal<"\"}\""> &x) { return
// x; });
}
26 changes: 26 additions & 0 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,3 +1281,29 @@ def test_arg_return_type_hints(doc):
)
# TypeIs<T>
assert doc(m.check_type_is) == "check_type_is(arg0: object) -> TypeIs[float]"
# Literal without special characters
# assert (
# doc(m.identity_literal_x)
# == 'identity_literal_x(arg0: Literal["x"]) -> Literal["x"]'
# )
# The Following tests fail with `ImportError: Internal error while parsing type signature (2)`
# Literal with @
# assert (
# doc(m.identity_literal_at)
# == 'identity_literal_at(arg0: Literal["@"]) -> Literal["@"]'
# )
# Literal with %
# assert (
# doc(m.identity_literal_percent)
# == 'identity_literal_percent(arg0: Literal["%"]) -> Literal["%"]'
# )
# Literal with {
# assert (
# doc(m.identity_literal_curly_open)
# == 'identity_literal_curly_open(arg0: Literal["{"]) -> Literal["{"]'
# )
# Literal with }
# assert (
# doc(m.identity_literal_curly_close)
# == 'identity_literal_curly_close(arg0: Literal["}"]) -> Literal["}"]'
# )

0 comments on commit 9877aca

Please sign in to comment.