Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224720?usp=email )
Change subject: ProofreadPage: Never use None as key in WeakKeyDictionary
......................................................................
ProofreadPage: Never use None as key in WeakKeyDictionary
Bug: T413563
Change-Id: Iffa326896906f757278a7e83f803a38c136f213d
---
M pywikibot/proofreadpage.py
1 file changed, 26 insertions(+), 0 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 92ce8a9..dbece5b 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -168,7 +168,15 @@
"""A descriptor tag.
+ Implements a data descriptor for attributes of <pages /> tags
+ (used in :class:`PagesTagParser`). Provides controlled access
+ to a single attribute value via a WeakKeyDictionary to store
+ per-instance da
+
.. versionadded:: 8.0
+ .. versionchanged:: 11.0
+ Never use None as key in WeakKeyDictionary. Class-level access
+ returns the descriptor itself.
"""
def __init__(self) -> None:
@@ -179,10 +187,27 @@
self.public_name = name
def __get__(self, obj, objtype=None):
+ """Retrieve the value of the attribute for a given instance.
+
+ .. versionchanged:: 11.0
+ If *obj* is None (e.g., when accessed via the class rather
+ than an instance), return the descriptor itself instead of
+ attempting to use None as a key in the WeakKeyDictionary.
+
+ :param obj: Instance of the class that owns this descriptor, or
+ None if accessed via the class.
+ :param objtype: Type of the class (unused).
+ :return: The attribute value for the instance, or the descriptor
+ itself if accessed via the class.
+ """
+ if obj is None:
+ return self
+
attr = self.attrs.get(obj)
return attr.value if attr is not None else None
def __set__(self, obj, value) -> None:
+ """Set attribute value for the given instance."""
attr = self.attrs.get(obj)
if attr is not None:
attr.value = value
@@ -190,6 +215,7 @@
self.attrs[obj] = TagAttr(self.public_name, value)
def __delete__(self, obj):
+ """Delete attribute for the given instance."""
self.attrs.pop(obj, None)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1224720?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Iffa326896906f757278a7e83f803a38c136f213d
Gerrit-Change-Number: 1224720
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]