Skip to content

Commit d12c025

Browse files
committed
Rename py::local to py::module_local
1 parent ac21545 commit d12c025

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

include/pybind11/attr.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct metaclass {
6565
};
6666

6767
/// Annotation that marks a class as local to the module:
68-
struct local { bool value; local(bool v = true) : value(v) { } };
68+
struct module_local { bool value; module_local(bool v = true) : value(v) { } };
6969

7070
/// Annotation to mark enums as an arithmetic type
7171
struct arithmetic { };
@@ -199,7 +199,7 @@ struct function_record {
199199
/// Special data structure which (temporarily) holds metadata about a bound class
200200
struct type_record {
201201
PYBIND11_NOINLINE type_record()
202-
: multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false), local(false) { }
202+
: multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false), module_local(false) { }
203203

204204
/// Handle to the parent scope
205205
handle scope;
@@ -247,7 +247,7 @@ struct type_record {
247247
bool default_holder : 1;
248248

249249
/// Is the class definition local to the module shared object?
250-
bool local : 1;
250+
bool module_local : 1;
251251

252252
PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *)) {
253253
auto base_info = detail::get_type_info(base, false);
@@ -415,8 +415,8 @@ struct process_attribute<metaclass> : process_attribute_default<metaclass> {
415415
};
416416

417417
template <>
418-
struct process_attribute<local> : process_attribute_default<local> {
419-
static void init(const local &l, type_record *r) { r->local = l.value; }
418+
struct process_attribute<module_local> : process_attribute_default<module_local> {
419+
static void init(const module_local &l, type_record *r) { r->module_local = l.value; }
420420
};
421421

422422
/// Process an 'arithmetic' attribute for enums (does nothing here)

include/pybind11/pybind11.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ class generic_type : public object {
844844
auto tindex = std::type_index(*rec.type);
845845
tinfo->direct_conversions = &internals.direct_conversions[tindex];
846846
tinfo->default_holder = rec.default_holder;
847-
if (rec.local)
847+
if (rec.module_local)
848848
registered_local_types_cpp()[tindex] = tinfo;
849849
else
850850
internals.registered_types_cpp[tindex] = tinfo;
@@ -989,7 +989,7 @@ class class_ : public detail::generic_type {
989989
generic_type::initialize(record);
990990

991991
if (has_alias) {
992-
auto &instances = record.local ? registered_local_types_cpp() : get_internals().registered_types_cpp;
992+
auto &instances = record.module_local ? registered_local_types_cpp() : get_internals().registered_types_cpp;
993993
instances[std::type_index(typeid(type_alias))] = instances[std::type_index(typeid(type))];
994994
}
995995
}
@@ -1438,7 +1438,7 @@ iterator make_iterator(Iterator first, Sentinel last, Extra &&... extra) {
14381438
typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state;
14391439

14401440
if (!detail::get_type_info(typeid(state), false)) {
1441-
class_<state>(handle(), "iterator", pybind11::local())
1441+
class_<state>(handle(), "iterator", pybind11::module_local())
14421442
.def("__iter__", [](state &s) -> state& { return s; })
14431443
.def("__next__", [](state &s) -> ValueType {
14441444
if (!s.first_or_done)
@@ -1467,7 +1467,7 @@ iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) {
14671467
typedef detail::iterator_state<Iterator, Sentinel, true, Policy> state;
14681468

14691469
if (!detail::get_type_info(typeid(state), false)) {
1470-
class_<state>(handle(), "iterator", pybind11::local())
1470+
class_<state>(handle(), "iterator", pybind11::module_local())
14711471
.def("__iter__", [](state &s) -> state& { return s; })
14721472
.def("__next__", [](state &s) -> KeyType {
14731473
if (!s.first_or_done)

include/pybind11/stl_bind.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ template <typename Vector, typename holder_type = std::unique_ptr<Vector>, typen
379379
class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, Args&&... args) {
380380
using Class_ = class_<Vector, holder_type>;
381381

382-
Class_ cl(scope, name.c_str(), pybind11::local(), std::forward<Args>(args)...);
382+
Class_ cl(scope, name.c_str(), pybind11::module_local(), std::forward<Args>(args)...);
383383

384384
// Declare the buffer interface if a buffer_protocol() is passed in
385385
detail::vector_buffer<Vector, Class_, Args...>(cl);
@@ -536,7 +536,7 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&.
536536
using MappedType = typename Map::mapped_type;
537537
using Class_ = class_<Map, holder_type>;
538538

539-
Class_ cl(scope, name.c_str(), pybind11::local(), std::forward<Args>(args)...);
539+
Class_ cl(scope, name.c_str(), pybind11::module_local(), std::forward<Args>(args)...);
540540

541541
cl.def(init<>());
542542

tests/pybind11_local_bindings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ PYBIND11_MODULE(pybind11_local_bindings, m) {
1919

2020
// test_local_bindings
2121
// Local to both:
22-
bind_local<LocalType, 1>(m, "LocalType", py::local())
22+
bind_local<LocalType, 1>(m, "LocalType", py::module_local())
2323
.def("get2", [](LocalType &t) { return t.i + 2; })
2424
;
2525

@@ -34,20 +34,20 @@ PYBIND11_MODULE(pybind11_local_bindings, m) {
3434
});
3535

3636
// test_stl_bind_local
37-
// stl_bind.h binders defaults to py::local. Note that the value doesn't have to be local, even
37+
// stl_bind.h binders defaults to py::module_local. Note that the value doesn't have to be local, even
3838
// if the overall container is:
3939
py::bind_vector<std::vector<LocalType>>(m, "LocalVec");
4040
py::bind_vector<std::vector<NonLocalType>>(m, "LocalVec2");
4141
py::bind_map<std::unordered_map<std::string, LocalType>>(m, "LocalMap");
4242
py::bind_map<std::unordered_map<std::string, NonLocalType>>(m, "LocalMap2");
4343

4444
// test_stl_bind_global
45-
// stl_bind binders can, however, be overridden to global using `py::local(false)` (in which
45+
// stl_bind binders can, however, be overridden to global using `py::module_local(false)` (in which
4646
// case this will fail):
4747
m.def("register_nonlocal_stl1", [m]() {
48-
py::bind_vector<std::vector<NonLocal2>>(m, "NonLocalVec", py::local(false));
48+
py::bind_vector<std::vector<NonLocal2>>(m, "NonLocalVec", py::module_local(false));
4949
});
5050
m.def("register_nonlocal_stl2", [m]() {
51-
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::local(false));
51+
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::module_local(false));
5252
});
5353
}

tests/test_class.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ TEST_SUBMODULE(class_, m) {
228228

229229
// This test is actually part of test_local_bindings (test_duplicate_local), but we need a
230230
// definition in a different compilation unit within the same module:
231-
bind_local<LocalExternal, 17>(m, "LocalExternal", py::local());
231+
bind_local<LocalExternal, 17>(m, "LocalExternal", py::module_local());
232232
}
233233

234234
template <int N> class BreaksBase {};

tests/test_local_bindings.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
tests/test_local_bindings.cpp -- tests the py::local class feature which makes a class binding
3-
local to the module in which it is defined.
2+
tests/test_local_bindings.cpp -- tests the py::module_local class feature which makes a class
3+
binding local to the module in which it is defined.
44
55
Copyright (c) 2017 Jason Rhinelander <[email protected]>
66
@@ -15,8 +15,8 @@
1515
TEST_SUBMODULE(local_bindings, m) {
1616

1717
// test_local_bindings
18-
// Register a class with py::local:
19-
bind_local<LocalType, -1>(m, "LocalType", py::local())
18+
// Register a class with py::module_local:
19+
bind_local<LocalType, -1>(m, "LocalType", py::module_local())
2020
.def("get3", [](LocalType &t) { return t.i + 3; })
2121
;
2222

@@ -31,28 +31,28 @@ TEST_SUBMODULE(local_bindings, m) {
3131
;
3232

3333
// test_duplicate_local
34-
// py::local declarations should be visible across compilation units that get linked together;
34+
// py::module_local declarations should be visible across compilation units that get linked together;
3535
// this tries to register a duplicate local. It depends on a definition in test_class.cpp and
3636
// should raise a runtime error from the duplicate definition attempt. If test_class isn't
3737
// available it *also* throws a runtime error (with "test_class not enabled" as value).
3838
m.def("register_local_external", [m]() {
3939
auto main = py::module::import("pybind11_tests");
4040
if (py::hasattr(main, "class_")) {
41-
bind_local<LocalExternal, 7>(m, "LocalExternal", py::local());
41+
bind_local<LocalExternal, 7>(m, "LocalExternal", py::module_local());
4242
}
4343
else throw std::runtime_error("test_class not enabled");
4444
});
4545

4646
// test_stl_bind_local
47-
// stl_bind.h binders defaults to py::local:
47+
// stl_bind.h binders defaults to py::module_local:
4848
py::bind_vector<std::vector<LocalType>>(m, "LocalVec");
4949
py::bind_vector<std::vector<NonLocalType>>(m, "LocalVec2");
5050
py::bind_map<std::unordered_map<std::string, LocalType>>(m, "LocalMap");
5151
py::bind_map<std::unordered_map<std::string, NonLocalType>>(m, "LocalMap2");
5252

5353
// test_stl_bind_global
54-
// They can, however, be overridden to global using `py::local(false)`:
54+
// They can, however, be overridden to global using `py::module_local(false)`:
5555
bind_local<NonLocal2, 10>(m, "NonLocal2");
56-
py::bind_vector<std::vector<NonLocal2>>(m, "NonLocalVec", py::local(false));
57-
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::local(false));
56+
py::bind_vector<std::vector<NonLocal2>>(m, "NonLocalVec", py::module_local(false));
57+
py::bind_map<std::unordered_map<std::string, NonLocal2>>(m, "NonLocalMap", py::module_local(false));
5858
}

0 commit comments

Comments
 (0)