mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
Compare commits
8 Commits
e1dd502ed0
...
7ec4eec983
Author | SHA1 | Date | |
---|---|---|---|
|
7ec4eec983 | ||
|
a14c936562 | ||
|
eb2ecf1033 | ||
|
549f3b7e54 | ||
|
f4ee39c229 | ||
|
726918d74a | ||
|
ae3cfa82cc | ||
|
9c8df99e40 |
@ -1301,6 +1301,21 @@ public:
|
||||
// For Python 2, reinterpret_borrow was correct.
|
||||
return reinterpret_borrow<module_>(m);
|
||||
}
|
||||
|
||||
struct strip_leading_underscore_from_name {};
|
||||
|
||||
module_ make_alias(const char *name) {
|
||||
module_ ret = *this;
|
||||
ret.attr("__name__") = name;
|
||||
return ret;
|
||||
}
|
||||
|
||||
module_ make_alias(strip_leading_underscore_from_name) {
|
||||
const char *name = PyModule_GetName(*this);
|
||||
if (name && name[0] == '_')
|
||||
name += 1;
|
||||
return make_alias(name);
|
||||
}
|
||||
};
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
|
22
tests/test_make_alias.cpp
Normal file
22
tests/test_make_alias.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
tests/make_alias -- make alias
|
||||
|
||||
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
|
||||
|
||||
All rights reserved. Use of this source code is governed by a
|
||||
BSD-style license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
#include "constructor_stats.h"
|
||||
#include "pybind11_tests.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(disable : 4996) // C4996: std::unary_negation is deprecated
|
||||
#endif
|
||||
|
||||
TEST_SUBMODULE(_make_alias, m) {
|
||||
ma = m.make_alias(pybind11::module::strip_leading_underscore_from_name{});
|
||||
ma.def("foo", []() -> {});
|
||||
}
|
9
tests/test_make_alias.py
Normal file
9
tests/test_make_alias.py
Normal file
@ -0,0 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from pybind11_tests import ConstructorStats
|
||||
|
||||
m = pytest.importorskip("pybind11_tests._make_alias")
|
||||
|
||||
|
||||
def assert_name(mat):
|
||||
assert m.__name__ == "make_alias"
|
Loading…
Reference in New Issue
Block a user