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
register contextvars.Context to collections.abc.Mapping #126451
contextvars.Context is documented as implementing the collections.abc.Mapping interface. I believe we should register it to the abc, so an isinstance check can work.
I was too :)
But, we backported #126419
So, I decided to be consistent. If you think that these backports should be reverted - then I have no objections :)
The decision to backport is on me -- I applied the backport labels to both PRs. But I also don't feel strongly, and am fine with the backports being reverted if you disagree with them!
FWIW, my thinking was:
I think this class was always meant to implement a mapping API, and I think it was just an oversight (a micro-bug, IMO) that it was never explicitly registered to the ABC
I couldn't see any risk of breakage from doing so; it seemed very low-risk
But as I said in #126419 (comment), it feels very borderline to me, so I'm very happy to revert the backports if others disagree!
The risky aspect to me is that isinstance(..., Mapping) will start behaving differently in a patch release. That may have unexpected effects for some users.
The failing tests in #126674 and #126675 seem to validate folks' concerns about the backports of these PRs. I'll open a revert PR for the backports tomorrow.
Reacted by Gregory P. Smith, Jelle Zijlstra, Shantanu and Andrew Svetlov
Activity
JelleZijlstra commentedon Nov 5, 2024
Could you list out all the methods on Mapping to confirm it really conforms with the interface? I'd like to prevent another case similar to #125420.
tungol commentedon Nov 5, 2024
Sure.
Mapping methods are:
__getitem__,__iter__,__len__,__contains__,keys,items,values,get,__eq__, and__ne__. All are present on Context:gh-126451: Register contextvars.Context to collections.abc.Mapping (#…
pythongh-126451: Register contextvars.Context to collections.abc.Mapp…
pythongh-126451: Register contextvars.Context to collections.abc.Mapp…
[3.12] gh-126451: Register contextvars.Context to collections.abc.Map…
[3.13] gh-126451: Register contextvars.Context to collections.abc.Map…
hauntsaninja commentedon Nov 6, 2024
I was surprised that we backported this
sobolevn commentedon Nov 7, 2024
I was too :)
But, we backported #126419
So, I decided to be consistent. If you think that these backports should be reverted - then I have no objections :)
AlexWaygood commentedon Nov 7, 2024
The decision to backport is on me -- I applied the backport labels to both PRs. But I also don't feel strongly, and am fine with the backports being reverted if you disagree with them!
FWIW, my thinking was:
But as I said in #126419 (comment), it feels very borderline to me, so I'm very happy to revert the backports if others disagree!
JelleZijlstra commentedon Nov 7, 2024
The risky aspect to me is that
isinstance(..., Mapping)will start behaving differently in a patch release. That may have unexpected effects for some users.tungol commentedon Nov 7, 2024
As the person who kicked this off: I have no opinion about the backports.
AlexWaygood commentedon Nov 11, 2024
The failing tests in #126674 and #126675 seem to validate folks' concerns about the backports of these PRs. I'll open a revert PR for the backports tomorrow.
AlexWaygood commentedon Nov 11, 2024
Thanks everybody for voicing your concerns! I appreciate it.
Revert "[3.13] pythongh-126451: Register contextvars.Context to colle…
Revert "[3.12] pythongh-126451: Register contextvars.Context to colle…
AlexWaygood commentedon Nov 12, 2024
Backports are being reverted in:
contextvars.Contextand multiprocessing proxies #126734[3.12] gh-126451: Revert backports of ABC registrations for contextva…
[3.13] gh-126451: Revert backports of ABC registrations for `contextv…
pythongh-126451: Register contextvars.Context to collections.abc.Mapp…
pythongh-126451: Register contextvars.Context to collections.abc.Mapp…