mirror of https://github.com/pybind/pybind11.git
Compare commits
8 Commits
e1dd502ed0
...
7ec4eec983
Author | SHA1 | Date |
---|---|---|
Tom de Geus | 7ec4eec983 | |
Tom de Geus | a14c936562 | |
Tom de Geus | eb2ecf1033 | |
Tom de Geus | 549f3b7e54 | |
Tom de Geus | f4ee39c229 | |
Tom de Geus | 726918d74a | |
pre-commit-ci[bot] | ae3cfa82cc | |
Tom de Geus | 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)
|
||||
|
|
|
@ -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", []() -> {});
|
||||
}
|
|
@ -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