Skip to content

Commit 602fbba

Browse files
Make PyDict iterator compatible with free-threaded build (#4439)
* Iterate over dict items in `DictIterator` * Use python instead of C API to get dict items * Use plain dict iterator when not on free-threaded & not a subclass * Copy dict on free-threaded builds to prevent concurrent modifications * Add test for dict subclass iters * Implement `PyDict::locked_for_each` * Lock `BoundDictIterator::next` on each iteration * Implement locked `fold` & `try_fold` * Implement `all`,`any`,`find`,`find_map`,`position` when not on nightly * Add changelog * Use critical section wrapper * Make `dict::locked_for_each` available on all builds * Remove item() iter * Add tests for `PyDict::iter()` reducers * Add more docs to locked_for_each * Move iter implementation into inner struct
1 parent 96c31e7 commit 602fbba

File tree

3 files changed

+355
-57
lines changed

3 files changed

+355
-57
lines changed

newsfragments/4439.changed.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Make `PyDict` iterator compatible with free-threaded build
2+
* Added `PyDict::locked_for_each` method to iterate on free-threaded builds to prevent the dict being mutated during iteration
3+
* Iterate over `dict.items()` when dict is subclassed from `PyDict`

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![warn(missing_docs)]
2-
#![cfg_attr(feature = "nightly", feature(auto_traits, negative_impls))]
2+
#![cfg_attr(
3+
feature = "nightly",
4+
feature(auto_traits, negative_impls, try_trait_v2)
5+
)]
36
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
47
// Deny some lints in doctests.
58
// Use `#[allow(...)]` locally to override.

0 commit comments

Comments
 (0)