mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-19 01:15:52 +00:00
try setattr
This commit is contained in:
parent
d660177409
commit
fe21e0f8d7
@ -2571,11 +2571,10 @@ template <typename D>
|
||||
object object_api<D>::annotations() const {
|
||||
// Python 3.8, 3.9
|
||||
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9
|
||||
if (hasattr(derived(), "__dict__")) {
|
||||
return getattr(getattr(derived(), "__dict__"), "__annotations__", dict());
|
||||
} else {
|
||||
return getattr(derived(), "__annotations__", dict());
|
||||
if (!hasattr(derived(), "__annotations__")) {
|
||||
setattr(derived(), "__annotations__", dict());
|
||||
}
|
||||
return attr("__annotations__");
|
||||
// Python 3.10+
|
||||
#else
|
||||
return getattr(derived(), "__annotations__", dict());
|
||||
|
@ -1125,7 +1125,6 @@ def test_class_attribute_types() -> None:
|
||||
assert empty_annotations == {}
|
||||
assert annotations["x"] == "float"
|
||||
assert annotations["dict_str_int"] == "dict[str, int]"
|
||||
assert False
|
||||
|
||||
|
||||
def test_final_annotation() -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user