17 Commits

Author SHA1 Message Date
Changjoon
330b18f2fe Preserve recursively-set value in defaultdict.__missing__ (#7718)
CPython's defaultdict.__missing__ (Modules/_collectionsmodule.c::defdict_missing)
calls default_factory() first; if the factory's recursion already populated
self[key] while running, the existing value is preserved instead of being
overwritten.

RustPython ships a Python fallback at Lib/collections/_defaultdict.py
(the C _collections.defaultdict is not available). That fallback
unconditionally executed self[key] = val after the factory returned,
overwriting any value the recursive call had already stored.

Add a 'if key in self: return self[key]' guard before the assignment.
dict.__contains__ does not invoke __missing__, so there's no recursion
risk; in the common non-reentrant case the check is False and behavior
is unchanged.

Unmasks test_defaultdict.TestDefaultDict.test_factory_conflict_with_set_value.
2026-04-29 18:14:32 +09:00
github-actions[bot]
16bb1040b4 Update collections from v3.14.3 (#7135)
- Updated Lib/collections from CPython v3.14.3
- Preserved RustPython's fallback implementation for defaultdict
- Added test for update_reentrant_add_clears_counter
- Minor formatting fixes in test file

Co-authored-by: CPython Developers <>
2026-02-14 21:35:25 +09:00
Lee Dogeon
3bcd071e4d Bump collections to 3.14.2 (#6770)
* Bump collections to 3.14.2

* Unmark resolved tests
2026-01-20 23:58:43 +09:00
Daniel Chiquito
bcb35919a4 Update collections/__init__.py to 3.12.2 2024-02-23 20:14:41 -05:00
Joshua Mankelow
32aa9933be Updated __init__.py to be inline with CPython 3.11.2 2023-04-20 15:20:36 +09:00
Gyubong Lee
9c2a5041e9 Reflect feedbacks 2022-07-22 13:16:12 +09:00
Gyubong Lee
3c9e92cebb Add or, ror andior to defaultdict 2022-07-22 12:16:13 +09:00
CPython developers
9537149572 Update collections/test_{collections,defaultdict} from CPython 3.10.5 2022-07-18 03:54:49 +09:00
Chris Moradi
6abfc3a00c Revert UserDict.__init__ changes, new passing test of UserList 2021-10-25 22:41:59 -07:00
Chris Moradi
ec247e0d4f Update collections from CPython, fix tests for UserDict/List/String
Clean implementation of changes in PR #3371 based on feedback.

Copies from [CPython tag `v3.9.7` and adds back custom RustPython changes where needed for:
- `Lib/collections/__init__.py`
- `Lib/test/test_collections.py`

Closes: #3371
2021-10-25 21:19:44 -07:00
Noah
3c3801bbe4 Improve defaultdict some more 2021-04-11 17:38:44 -05:00
Noah
1b3408f00d Fix defaultdict 2021-04-11 17:38:44 -05:00
Noah
f8d39cc648 Fix defaultdict 2020-10-07 19:29:41 -05:00
coolreader18
14e3ebe48f Add selectors module from CPython 3.6 2019-10-23 17:53:51 +00:00
coolreader18
9ec6660c09 Add argparse and gettext modules 2019-07-19 22:38:09 -05:00
coolreader18
5e5d726a5d Add defaultdict to collections 2019-07-10 22:16:37 -05:00
coolreader18
c78c95f03a Add CPython library modules needed for unittest 2019-06-26 11:39:10 -05:00