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

Change subject: classproperty: Prevent setting properties on instances
......................................................................

classproperty: Prevent setting properties on instances

Change-Id: I7a868d9bd53cca906b23b03266d38254d04caf47
---
M pywikibot/tools/__init__.py
1 file changed, 9 insertions(+), 1 deletion(-)

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




diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 26301bb..b898b8d 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -172,9 +172,12 @@
             def bar(cls):  # a class property method
                 return cls._bar

-    Foo.bar gives 'baz'.
+    Accessing :code:`Foo.bar` gives :code:`'baz'`. Setting a class
+    property on an instance raises :exc:`AttributeError`.

     .. version-added:: 3.0
+    .. version-changed:: 11.9
+       Prevent setting a class property on an instance.
     """

     def __init__(self, cls_method) -> None:
@@ -202,6 +205,11 @@

         return self.method(owner)

+    def __set__(self, instance, value) -> None:
+        """Prevent setting a class property on an instance."""
+        raise AttributeError(
+            f"can't set attribute {self.method.__name__!r}")
+

 class suppress_warnings(catch_warnings):  # noqa: N801


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1354167?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: I7a868d9bd53cca906b23b03266d38254d04caf47
Gerrit-Change-Number: 1354167
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mahveotm <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to