You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Free-threading list.__getitem__ may return an item that was never in the list #162881
The if (ob_item != atomic_load(&a->ob_item)) check in the proposed implementation in the PEP is missing from the actual implementation.
I'd say it is a bug because IIUC it's possible that:
thread A calls list_get_item_ref(L, i) and sees item == O
thread B calls L.append(...) and resizes L
thread C calls L[i] = P and frees O
some thread allocates a new object at location O
thread A increfs the new object at O, checks that the old ob_item[i] contains O, which it still does because P was stored after the resize, and returns it.
Therefore, the call to list_get_item_ref(L, i) returned an object that was possibly never contained in L.
I can't make out from the conversation in the PR why the check was removed in d5d39ec.
Activity
dpdani commentedon Nov 30, 2026
I haven't actually run a test to demonstrate this.