mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-28 22:02:43 +00:00
comments and function name cleanup
This commit is contained in:
parent
adfed511e2
commit
9160cb1af5
@ -1334,7 +1334,7 @@ object object_or_cast(T &&o) {
|
|||||||
// Written here so make_caster<T> can be used
|
// Written here so make_caster<T> can be used
|
||||||
template <typename D>
|
template <typename D>
|
||||||
template <typename T>
|
template <typename T>
|
||||||
str_attr_accessor object_api<D>::attr_with_type(const char *key) const {
|
str_attr_accessor object_api<D>::attr_with_type_hint(const char *key) const {
|
||||||
annotations()[key] = make_caster<T>::name.text;
|
annotations()[key] = make_caster<T>::name.text;
|
||||||
return {derived(), key};
|
return {derived(), key};
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ public:
|
|||||||
str_attr_accessor attr(const char *key) const;
|
str_attr_accessor attr(const char *key) const;
|
||||||
|
|
||||||
#if defined(PYBIND11_CPP17)
|
#if defined(PYBIND11_CPP17)
|
||||||
// attr_with_type is implemented in cast.h:
|
// attr_with_type_hint is implemented in cast.h:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
str_attr_accessor attr_with_type(const char *key) const;
|
str_attr_accessor attr_with_type_hint(const char *key) const;
|
||||||
#endif
|
#endif
|
||||||
/** \rst
|
/** \rst
|
||||||
Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple``
|
Matches * unpacking in Python, e.g. to unpack arguments out of a ``tuple``
|
||||||
@ -2567,16 +2567,13 @@ str_attr_accessor object_api<D>::doc() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename D>
|
template <typename D>
|
||||||
// Always a dict
|
|
||||||
// https://docs.python.org/3/howto/annotations.html#accessing-the-annotations-dict-of-an-object-in-python-3-9-and-older
|
|
||||||
object object_api<D>::annotations() const {
|
object object_api<D>::annotations() const {
|
||||||
// Python 3.8, 3.9
|
|
||||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9
|
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9
|
||||||
|
// https://docs.python.org/3/howto/annotations.html#accessing-the-annotations-dict-of-an-object-in-python-3-9-and-older
|
||||||
if (!hasattr(derived(), "__annotations__")) {
|
if (!hasattr(derived(), "__annotations__")) {
|
||||||
setattr(derived(), "__annotations__", dict());
|
setattr(derived(), "__annotations__", dict());
|
||||||
}
|
}
|
||||||
return attr("__annotations__");
|
return attr("__annotations__");
|
||||||
// Python 3.10+
|
|
||||||
#else
|
#else
|
||||||
return getattr(derived(), "__annotations__", dict());
|
return getattr(derived(), "__annotations__", dict());
|
||||||
#endif
|
#endif
|
||||||
|
@ -1000,8 +1000,8 @@ TEST_SUBMODULE(pytypes, m) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PYBIND11_CPP17)
|
#if defined(PYBIND11_CPP17)
|
||||||
m.attr_with_type<py::typing::List<int>>("list_int") = py::list();
|
m.attr_with_type_hint<py::typing::List<int>>("list_int") = py::list();
|
||||||
m.attr_with_type<py::typing::Set<py::str>>("set_str") = py::set();
|
m.attr_with_type_hint<py::typing::Set<py::str>>("set_str") = py::set();
|
||||||
|
|
||||||
struct Empty {};
|
struct Empty {};
|
||||||
py::class_<Empty>(m, "EmptyAnnotationClass");
|
py::class_<Empty>(m, "EmptyAnnotationClass");
|
||||||
@ -1011,10 +1011,10 @@ TEST_SUBMODULE(pytypes, m) {
|
|||||||
py::dict dict_str_int;
|
py::dict dict_str_int;
|
||||||
};
|
};
|
||||||
auto point = py::class_<Point>(m, "Point");
|
auto point = py::class_<Point>(m, "Point");
|
||||||
point.attr_with_type<float>("x");
|
point.attr_with_type_hint<float>("x");
|
||||||
point.attr_with_type<py::typing::Dict<py::str, int>>("dict_str_int") = py::dict();
|
point.attr_with_type_hint<py::typing::Dict<py::str, int>>("dict_str_int") = py::dict();
|
||||||
|
|
||||||
m.attr_with_type<py::typing::Final<int>>("CONST_INT") = 3;
|
m.attr_with_type_hint<py::typing::Final<int>>("CONST_INT") = 3;
|
||||||
m.attr("defined_PYBIND11_CPP17") = true;
|
m.attr("defined_PYBIND11_CPP17") = true;
|
||||||
#else
|
#else
|
||||||
m.attr("defined_PYBIND11_CPP17") = false;
|
m.attr("defined_PYBIND11_CPP17") = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user