Skip to content

feat(types): Allow setting types for attributes #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
aa74fbe
init
InvincibleRMC Dec 5, 2024
4c263c1
add comment
InvincibleRMC Dec 5, 2024
4788d8c
style: pre-commit fixes
pre-commit-ci[bot] Dec 5, 2024
bc8f095
fix extra ;
InvincibleRMC Dec 5, 2024
c38836a
Add annotation helper for older python versions
InvincibleRMC Dec 5, 2024
9e43986
style: pre-commit fixes
pre-commit-ci[bot] Dec 5, 2024
9f34dcc
test writing __annotations__ to __dict__
InvincibleRMC Dec 5, 2024
10d7b05
style: pre-commit fixes
pre-commit-ci[bot] Dec 5, 2024
6dff59f
revert bac to __annotations__
InvincibleRMC Dec 5, 2024
c8edd09
use getattr for automatic init
InvincibleRMC Dec 5, 2024
259ce93
use std::move
InvincibleRMC Dec 5, 2024
7e380e2
update helper
InvincibleRMC Dec 5, 2024
b8ad03d
remove stdmove
InvincibleRMC Dec 5, 2024
e5235f0
test isinstance
InvincibleRMC Dec 6, 2024
639b192
style: pre-commit fixes
pre-commit-ci[bot] Dec 6, 2024
8da0ce0
add #if 3.9
InvincibleRMC Dec 6, 2024
886c9c2
merge
InvincibleRMC Dec 6, 2024
31cc64f
style: pre-commit fixes
pre-commit-ci[bot] Dec 6, 2024
4d0968d
use getattr
InvincibleRMC Dec 6, 2024
e84df95
add dir
InvincibleRMC Dec 6, 2024
d660177
use hasattr
InvincibleRMC Dec 6, 2024
fe21e0f
try setattr
InvincibleRMC Dec 6, 2024
4a443a7
add c++17 guard
InvincibleRMC Dec 6, 2024
008c370
style: pre-commit fixes
pre-commit-ci[bot] Dec 6, 2024
b318d02
add compile guard
InvincibleRMC Dec 6, 2024
a53bf0e
style: pre-commit fixes
pre-commit-ci[bot] Dec 6, 2024
adfed51
cleanup
InvincibleRMC Dec 6, 2024
9160cb1
comments and function name cleanup
InvincibleRMC Dec 8, 2024
1571d52
Merge remote-tracking branch 'origin/master' into attribute-types
InvincibleRMC Dec 8, 2024
07f8613
style: pre-commit fixes
pre-commit-ci[bot] Dec 8, 2024
14d2dda
update test case
InvincibleRMC Dec 15, 2024
881b356
style: pre-commit fixes
pre-commit-ci[bot] Dec 15, 2024
731745a
add write
InvincibleRMC Dec 15, 2024
048b539
Merge branch 'master' into attribute-types
InvincibleRMC Dec 15, 2024
890fcae
added instance check
InvincibleRMC Dec 15, 2024
28d2a66
style: pre-commit fixes
pre-commit-ci[bot] Dec 15, 2024
3cbaafd
Test for `__cpp_inline_variables` and use `static_assert()`
rwgk Dec 17, 2024
58e5a09
Add guard: __annotations__["list_int"] was set already.
rwgk Dec 17, 2024
882d20f
Avoid explicit `false` in `static_assert()`.
rwgk Dec 17, 2024
b296137
add redeclaration test
InvincibleRMC Dec 19, 2024
981e0a3
style: pre-commit fixes
pre-commit-ci[bot] Dec 19, 2024
7f7b70b
add handle support to attr_with_type_hint
InvincibleRMC Dec 19, 2024
19e033c
store reintpreted_key
InvincibleRMC Dec 19, 2024
375ea30
style: pre-commit fixes
pre-commit-ci[bot] Dec 19, 2024
9f532cf
fix str namespace
InvincibleRMC Dec 19, 2024
8b241f1
fix scope?
InvincibleRMC Dec 19, 2024
f205bb4
string wrap
InvincibleRMC Dec 19, 2024
a6ffbe3
clang tidy
InvincibleRMC Dec 19, 2024
cd4f771
Swap order of attr_with_type_hint implementation in cast.h (so that t…
rwgk Dec 20, 2024
08d4774
Reuse `const char *` overload from `handle` overload.
rwgk Dec 20, 2024
1582971
Added comment
InvincibleRMC Dec 20, 2024
fe04344
style: pre-commit fixes
pre-commit-ci[bot] Dec 20, 2024
988c039
line up comment
InvincibleRMC Dec 20, 2024
2241892
fixed spelling error
InvincibleRMC Dec 20, 2024
4be50fe
Add missing period
InvincibleRMC Dec 20, 2024
8f87e21
Introduce `detail::always_false<>` to make the new `static_assert()` …
rwgk Dec 21, 2024
e6b1370
Copy `attr` comment for `const char *` overload, for consistency.
rwgk Dec 21, 2024
999b668
static_assert(std::false_type::value, ...)
rwgk Dec 21, 2024
9d46b4d
Revert "static_assert(std::false_type::value, ...)"
rwgk Dec 21, 2024
921657a
Add comment for `always_false`
rwgk Dec 21, 2024
e1e2c9a
add test for inspect.get_annotations()
InvincibleRMC Dec 21, 2024
2774a8d
style: pre-commit fixes
pre-commit-ci[bot] Dec 21, 2024
6a6bff8
Merge branch 'master' into attribute-types
InvincibleRMC Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove stdmove
  • Loading branch information
InvincibleRMC committed Dec 5, 2024
commit b8ad03da76ea64e9fc37ff1ff399f486f2484ad1
3 changes: 1 addition & 2 deletions include/pybind11/pytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,7 @@ str_attr_accessor object_api<D>::doc() const {
template <typename D>
// Always a dict
object object_api<D>::annotations() const {
dict annotations_dict = getattr(derived(), "__annotations__", dict());
return std::move(annotations_dict);
return getattr(derived(), "__annotations__", dict());
}

template <typename D>
Expand Down
1 change: 1 addition & 0 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ def test_dict_ranges(tested_dict, expected):


def get_annotations_helper(o):
print(help(o))
return getattr(o, "__annotations__", None)


Expand Down
Loading