forked from pybind/pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Experiment]
std::type_index
& unnamed namespace
Related to PRs pybind#4313, pybind#4315
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Nov 6, 2022
1 parent
ee2b522
commit 282eb72
Showing
6 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <pybind11/stl.h> | ||
|
||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_a, m) { | ||
m.attr("name") = "A"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry[std::type_index(typeid(any_struct))] | ||
.push_back("A"); | ||
|
||
m.def("std_type_index_registry_dump", []() { | ||
py::list items; | ||
for (const auto &it : py::detail::get_internals().std_type_index_registry) { | ||
items.append(py::make_tuple(it.first.name(), it.second)); | ||
} | ||
return items; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
from pybind11_tests import unnamed_namespace_a as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "A" | ||
reg = m.std_type_index_registry_dump() | ||
if len(reg) == 1: | ||
assert tuple(sorted(reg[0][1])) == ("A", "B") | ||
pytest.skip("std::type_index-EQ-BAD") | ||
if len(reg) == 2: | ||
assert tuple(sorted([reg[0][1][0], reg[1][1][0]])) == ("A", "B") | ||
pytest.skip("std::type_index-NE-GOOD") | ||
assert reg is None # Sure to fail. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace { | ||
struct any_struct {}; | ||
} // namespace | ||
|
||
TEST_SUBMODULE(unnamed_namespace_b, m) { | ||
m.attr("name") = "B"; | ||
|
||
py::detail::get_internals() | ||
.std_type_index_registry[std::type_index(typeid(any_struct))] | ||
.push_back("B"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pybind11_tests import unnamed_namespace_b as m | ||
|
||
|
||
def test_inspect(): | ||
assert m.name == "B" |