Unverified Commit f980d76d authored by Yannick Jadoul's avatar Yannick Jadoul Committed by GitHub
Browse files

Change NAMESPACE_* macros into PYBIND11_NAMESPACE_* (#2283)



* Change NAMESPACE_BEGIN and NAMESPACE_END macros into PYBIND11_NAMESPACE_BEGIN and PYBIND11_NAMESPACE_END

* Fix sudden HomeBrew 'python not installed' error

* Sweep difference in 'Class.__init__() must be called when overriding __init__' error message between CPython and PyPy under the rug

* Homebrew updated to 3.8 yesterday.
Co-authored-by: default avatarHenry Schreiner <HenrySchreinerIII@gmail.com>
parent 0d70f0e1
......@@ -50,7 +50,7 @@
# include <cxxabi.h>
#endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/// Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object
class cpp_function : public function {
......@@ -909,7 +909,7 @@ inline dict globals() {
return reinterpret_borrow<dict>(p ? p : module::import("__main__").attr("__dict__").ptr());
}
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
/// Generic support for creating new Python heap types
class generic_type : public object {
template <typename...> friend class class_;
......@@ -1047,7 +1047,7 @@ inline void call_operator_delete(void *p, size_t s, size_t a) {
#endif
}
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/// Given a pointer to a member function, cast it to its `Derived` version.
/// Forward everything else unchanged.
......@@ -1425,7 +1425,7 @@ detail::initimpl::pickle_factory<GetState, SetState> pickle(GetState &&g, SetSta
return {std::forward<GetState>(g), std::forward<SetState>(s)};
}
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
struct enum_base {
enum_base(handle base, handle parent) : m_base(base), m_parent(parent) { }
......@@ -1576,7 +1576,7 @@ struct enum_base {
handle m_parent;
};
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/// Binds C++ enumerations and enumeration classes to Python
template <typename Type> class enum_ : public class_<Type> {
......@@ -1628,7 +1628,7 @@ private:
detail::enum_base m_base;
};
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
inline void keep_alive_impl(handle nurse, handle patient) {
......@@ -1698,7 +1698,7 @@ struct iterator_state {
bool first_or_done;
};
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/// Makes a python iterator from a first and past-the-end C++ InputIterator.
template <return_value_policy Policy = return_value_policy::reference_internal,
......@@ -1831,13 +1831,13 @@ public:
}
};
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
// Returns a reference to a function-local static exception object used in the simple
// register_exception approach below. (It would be simpler to have the static local variable
// directly in register_exception, but that makes clang <3.5 segfault - issue #1349).
template <typename CppException>
exception<CppException> &get_exception_object() { static exception<CppException> ex; return ex; }
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/**
* Registers a Python exception in `m` of the given `name` and installs an exception translator to
......@@ -1863,7 +1863,7 @@ exception<CppException> &register_exception(handle scope,
return ex;
}
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
auto strings = tuple(args.size());
for (size_t i = 0; i < args.size(); ++i) {
......@@ -1894,7 +1894,7 @@ PYBIND11_NOINLINE inline void print(tuple args, dict kwargs) {
if (kwargs.contains("flush") && kwargs["flush"].cast<bool>())
file.attr("flush")();
}
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
template <return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
void print(Args &&...args) {
......@@ -2203,7 +2203,7 @@ template <class T> function get_overload(const T *this_ptr, const char *name) {
#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn, ...) \
PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
# pragma warning(pop)
......
......@@ -14,14 +14,14 @@
#include <utility>
#include <type_traits>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
/* A few forward declarations */
class handle; class object;
class str; class iterator;
struct arg; struct arg_v;
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
class args_proxy;
inline bool isinstance_generic(handle obj, const std::type_info &tp);
......@@ -158,7 +158,7 @@ private:
bool rich_compare(object_api const &other, int value) const;
};
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/** \rst
Holds a reference to a Python object (no reference counting)
......@@ -311,9 +311,9 @@ template <typename T> T reinterpret_borrow(handle h) { return {h, object::borrow
\endrst */
template <typename T> T reinterpret_steal(handle h) { return {h, object::stolen_t{}}; }
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
inline std::string error_string();
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
/// Fetch and hold an error which was already set in Python. An instance of this is typically
/// thrown to propagate python-side errors back through C++ which can either be caught manually or
......@@ -446,7 +446,7 @@ inline ssize_t hash(handle obj) {
/// @} python_builtins
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
inline handle get_function(handle value) {
if (value) {
#if PY_MAJOR_VERSION >= 3
......@@ -520,7 +520,7 @@ private:
mutable object cache;
};
NAMESPACE_BEGIN(accessor_policies)
PYBIND11_NAMESPACE_BEGIN(accessor_policies)
struct obj_attr {
using key_type = object;
static object get(handle obj, handle key) { return getattr(obj, key); }
......@@ -597,7 +597,7 @@ struct tuple_item {
}
}
};
NAMESPACE_END(accessor_policies)
PYBIND11_NAMESPACE_END(accessor_policies)
/// STL iterator template used for tuple, list, sequence and dict
template <typename Policy>
......@@ -638,7 +638,7 @@ public:
friend bool operator<=(const It &a, const It &b) { return !(a > b); }
};
NAMESPACE_BEGIN(iterator_policies)
PYBIND11_NAMESPACE_BEGIN(iterator_policies)
/// Quick proxy class needed to implement ``operator->`` for iterators which can't return pointers
template <typename T>
struct arrow_proxy {
......@@ -711,7 +711,7 @@ private:
PyObject *key = nullptr, *value = nullptr;
ssize_t pos = -1;
};
NAMESPACE_END(iterator_policies)
PYBIND11_NAMESPACE_END(iterator_policies)
#if !defined(PYPY_VERSION)
using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>;
......@@ -770,7 +770,7 @@ class simple_collector;
template <return_value_policy policy = return_value_policy::automatic_reference>
class unpacking_collector;
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
// TODO: After the deprecated constructors are removed, this macro can be simplified by
// inheriting ctors: `using Parent::Parent`. It's not an option right now because
......@@ -1045,7 +1045,7 @@ private:
}
};
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
// Converts a value to the given unsigned type. If an error occurs, you get back (Unsigned) -1;
// otherwise you get back the unsigned long or unsigned long long value cast to (Unsigned).
// (The distinction is critically important when casting a returned -1 error value to some other
......@@ -1065,7 +1065,7 @@ Unsigned as_unsigned(PyObject *o) {
return v == (unsigned long long) -1 && PyErr_Occurred() ? (Unsigned) -1 : (Unsigned) v;
}
}
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
class int_ : public object {
public:
......@@ -1409,7 +1409,7 @@ inline iterator iter(handle obj) {
}
/// @} python_builtins
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
template <typename D> iterator object_api<D>::begin() const { return iter(derived()); }
template <typename D> iterator object_api<D>::end() const { return iterator::sentinel(); }
template <typename D> item_accessor object_api<D>::operator[](handle key) const {
......@@ -1490,5 +1490,5 @@ PYBIND11_MATH_OPERATOR_BINARY(operator>>=, PyNumber_InPlaceRshift)
#undef PYBIND11_MATH_OPERATOR_UNARY
#undef PYBIND11_MATH_OPERATOR_BINARY
NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
......@@ -48,8 +48,8 @@
# define PYBIND11_HAS_VARIANT 1
#endif
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for
/// forwarding a container element). Typically used indirect via forwarded_type(), below.
......@@ -374,14 +374,14 @@ template <typename... Ts>
struct type_caster<std::variant<Ts...>> : variant_caster<std::variant<Ts...>> { };
#endif
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
os << (std::string) str(obj);
return os;
}
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
#if defined(_MSC_VER)
#pragma warning(pop)
......
......@@ -15,8 +15,8 @@
#include <algorithm>
#include <sstream>
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
/* SFINAE helper class used by 'is_comparable */
template <typename T> struct container_traits {
......@@ -413,7 +413,7 @@ vector_buffer(Class_& cl) {
template <typename Vector, typename Class_, typename... Args>
enable_if_t<!detail::any_of<std::is_same<Args, buffer_protocol>...>::value> vector_buffer(Class_&) {}
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
//
// std::vector
......@@ -511,7 +511,7 @@ class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, A
// std::map, std::unordered_map
//
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(detail)
/* Fallback functions */
template <typename, typename, typename... Args> void map_if_insertion_operator(const Args &...) { }
......@@ -577,7 +577,7 @@ template <typename Map, typename Class_> auto map_if_insertion_operator(Class_ &
}
NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(detail)
template <typename Map, typename holder_type = std::unique_ptr<Map>, typename... Args>
class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&... args) {
......@@ -653,4 +653,4 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args&&.
return cl;
}
NAMESPACE_END(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
......@@ -53,13 +53,13 @@ public:
/// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context.
/// Used to test recursive casters (e.g. std::tuple, stl containers).
struct RValueCaster {};
NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(pybind11)
PYBIND11_NAMESPACE_BEGIN(detail)
template<> class type_caster<RValueCaster> {
public:
PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster"));
static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); }
static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); }
};
NAMESPACE_END(detail)
NAMESPACE_END(pybind11)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(pybind11)
......@@ -109,7 +109,10 @@ def test_inheritance_init(msg):
pass
with pytest.raises(TypeError) as exc_info:
Python()
assert msg(exc_info.value) == "m.class_.Pet.__init__() must be called when overriding __init__"
expected = ["m.class_.Pet.__init__() must be called when overriding __init__",
"Pet.__init__() must be called when overriding __init__"] # PyPy?
# TODO: fix PyPy error message wrt. tp_name/__qualname__?
assert msg(exc_info.value) in expected
# Multiple bases
class RabbitHamster(m.Rabbit, m.Hamster):
......@@ -118,8 +121,9 @@ def test_inheritance_init(msg):
with pytest.raises(TypeError) as exc_info:
RabbitHamster()
expected = "m.class_.Hamster.__init__() must be called when overriding __init__"
assert msg(exc_info.value) == expected
expected = ["m.class_.Hamster.__init__() must be called when overriding __init__",
"Hamster.__init__() must be called when overriding __init__"] # PyPy
assert msg(exc_info.value) in expected
def test_automatic_upcasting():
......
......@@ -68,8 +68,8 @@ public:
int value;
};
NAMESPACE_BEGIN(pybind11)
NAMESPACE_BEGIN(detail)
PYBIND11_NAMESPACE_BEGIN(pybind11)
PYBIND11_NAMESPACE_BEGIN(detail)
template <> struct type_caster<MoveOnlyInt> {
PYBIND11_TYPE_CASTER(MoveOnlyInt, _("MoveOnlyInt"));
bool load(handle src, bool) { value = MoveOnlyInt(src.cast<int>()); return true; }
......@@ -97,8 +97,8 @@ public:
operator CopyOnlyInt&() { return value; }
template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>;
};
NAMESPACE_END(detail)
NAMESPACE_END(pybind11)
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(pybind11)
TEST_SUBMODULE(copy_move_policies, m) {
// test_lacking_copy_ctor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment