jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/440725 )
Change subject: family: read `__init__` from `__dict__` and deprecate
......................................................................
family: read `__init__` from `__dict__` and deprecate
deprecated wrapper expect a pure function, but in Python 2.7,
reading the function as a class attribute returns a method bound to
the class (unbound method), which cannot have arbitrary attributes
assigned, and the deprecated wrapper errors out. Reading from
__dict__ should return the actual function regardless of the Python
version used. The existence of the __init__ key is verified prior
the the execution.
Bug: T197529
Change-Id: I2077c6b0fa95c3dc2da0f8c1c5e99d12372ebcb9
---
M pywikibot/family.py
1 file changed, 4 insertions(+), 2 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 7623698..a334fe5 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -60,8 +60,10 @@
# don't use hasattr() here. consider only the class itself
if '__init__' in cls.__dict__:
# Initializer deprecated. Families should be immutable and any
- # instance / class modification should go to allocator (__new__)
- cls.__init__ = deprecated(cls.__init__)
+ # instance / class modification should go to allocator (__new__).
+ # The function is read from __dict__ because deprecated expect a
+ # function and python 2.7 binds the method to the class.
+ cls.__init__ = deprecated(cls.__dict__['__init__'])
# Invoke initializer immediately and make initializer no-op.
# This is to avoid repeated initializer invokation on repeated
--
To view, visit
https://gerrit.wikimedia.org/r/440725
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I2077c6b0fa95c3dc2da0f8c1c5e99d12372ebcb9
Gerrit-Change-Number: 440725
Gerrit-PatchSet: 2
Gerrit-Owner: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot