jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/994696?usp=email )

Change subject: [cleanup] raise RuntimeError if a Family has an initializer
......................................................................

[cleanup] raise RuntimeError if a Family has an initializer

Family class are to be immutable. Therefore the __init__ initializer
is deprecated for more than 5 years. A FutureWarning was given since
Pywikibot 8.3. Now remove this deprecation warning and raise a
RuntimeError instead.

Change-Id: I664ef4ff906b38dbc96d6b01668bebda81db3934
---
M ROADMAP.rst
M docs/api_ref/family.rst
M pywikibot/family.py
3 files changed, 38 insertions(+), 24 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/ROADMAP.rst b/ROADMAP.rst
index 329b941..0e61df9 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -28,6 +28,8 @@
 Breaking changes and code cleanups
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

+* A RuntimeError will be raised if a :class:`family.Family` subclass has an 
``__init__`` initializer method.
+  :meth:`family.Family.__post_init__` classmethod can be used instead.
 * :class:`InteractiveReplace<bot_choice.InteractiveReplace>` was moved from 
:mod:`bot` to :mod:`bot_choice` module
 * ``userinterfaces.transliteration.transliterator`` was renamed to 
:class:`Transliterator
   <userinterfaces.transliteration.Transliterator>`
diff --git a/docs/api_ref/family.rst b/docs/api_ref/family.rst
index 3a61f22..9ba9afd 100644
--- a/docs/api_ref/family.rst
+++ b/docs/api_ref/family.rst
@@ -7,17 +7,6 @@

    .. autoclass:: Family

-      .. method:: __init__()
-
-         Initializer
-
-         .. deprecated:: 3.0.20180710
-            Use :meth:`__post_init__` instead.
-         .. versionchanged:: 8.3
-            A FutureWarning is printed instead of a ``NotImplementedWarning``.
-            The deprecation may be removed in a future release and a
-            ``RuntimeError`` will be thrown instead.
-
       .. method:: __post_init__()
          :classmethod:

diff --git a/pywikibot/family.py b/pywikibot/family.py
index 5c8dd28..968fcef 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -43,11 +43,22 @@

     """Parent singleton class for all wiki families.

+    Families are immutable and initializer is unsupported. Any class
+    modification should go to :meth:`__post_init__` class method.
+
+    .. versionchanged:: 3.0
+       the family class is immutable. Having an ``__init__`` initializer
+       method a ``NotImplementedWarning`` will be given.
     .. versionchanged:: 8.0
        ``alphabetic``, ``alphabetic_revised`` and ``fyinterwiki``
        attributes where removed.
     .. versionchanged:: 8.2
        :attr:`obsolete` setter was removed.
+    .. versionchanged:: 8.3
+       Having an initializer method a ``FutureWarning`` will be given.
+    .. versionchanged:: 9.0.0
+       raises RuntimeError if an initializer method was found;
+       :meth:`__post_init__` classmethod should be used instead.
     """

     def __new__(cls):
@@ -63,17 +74,12 @@

         # 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(instead='__post_init__() classmethod',
-                                      since='3.0.20180710')(cls.__init__)
+            raise RuntimeError(fill(
+                f'Family class {cls.__module__}.{cls.__name__} cannot be'
+                ' instantiated; use __post_init__() classmethod to modify'
+                ' your family class. Refer the documentation.', width=66))

-            # Invoke initializer immediately and make initializer no-op.
-            # This is to avoid repeated initializer invocation on repeated
-            # invocations of the metaclass's __call__.
-            cls.instance.__init__()
-            cls.__init__ = lambda self: None  # no-op
-        elif '__post_init__' not in cls.__dict__:
+        if '__post_init__' not in cls.__dict__:
             pass
         elif inspect.ismethod(cls.__post_init__):  # classmethod check
             cls.__post_init__()
@@ -87,11 +93,14 @@

     @classproperty
     def instance(cls):
-        """Get the singleton instance."""
-        # This is a placeholder to invoke allocator before it's allocated.
-        # Allocator will override this classproperty.
+        """Get the singleton instance.
+
+        This is a placeholder to invoke allocator before it's allocated.
+        Allocator will override this classproperty.
+        """
         return cls()

+    #: The family name
     name: str | None = None

     #: Not open for edits; stewards can still edit.

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/994696?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I664ef4ff906b38dbc96d6b01668bebda81db3934
Gerrit-Change-Number: 994696
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to