mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-07 17:32:00 +00:00
use getattr for automatic init
This commit is contained in:
parent
6dff59f0c9
commit
c8edd09f06
@ -186,8 +186,8 @@ public:
|
|||||||
/// Get or set the object's docstring, i.e. ``obj.__doc__``.
|
/// Get or set the object's docstring, i.e. ``obj.__doc__``.
|
||||||
str_attr_accessor doc() const;
|
str_attr_accessor doc() const;
|
||||||
|
|
||||||
/// Get or set the object's annotations, i.e. ``obj.__annotations``.
|
/// Get or set the object's annotations, i.e. ``obj.__annotations__``.
|
||||||
str_attr_accessor annotations() const;
|
object annotations() const;
|
||||||
|
|
||||||
/// Return the object's current reference count
|
/// Return the object's current reference count
|
||||||
ssize_t ref_count() const {
|
ssize_t ref_count() const {
|
||||||
@ -2566,12 +2566,9 @@ str_attr_accessor object_api<D>::doc() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename D>
|
template <typename D>
|
||||||
str_attr_accessor object_api<D>::annotations() const {
|
// Always a dict
|
||||||
str_attr_accessor annotations_dict = attr("__annotations__");
|
object object_api<D>::annotations() const {
|
||||||
// Create dict automatically
|
dict annotations_dict = getattr(derived(), "__annotations__", dict());
|
||||||
if (!isinstance<dict>(annotations_dict)) {
|
|
||||||
annotations_dict = dict();
|
|
||||||
}
|
|
||||||
return annotations_dict;
|
return annotations_dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user