Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13 compatibility #1777

Open
Daft-Freak opened this issue Feb 15, 2025 · 2 comments
Open

Python 3.13 compatibility #1777

Daft-Freak opened this issue Feb 15, 2025 · 2 comments

Comments

@Daft-Freak
Copy link
Contributor

Trying to run on python 3.13 results in:

[...]
    @app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>')
                      ~~~~~~~~^^^^^^^^^^^
TypeError: sequence item 12: expected str instance, method found

Where item 12 is:

<bound method LABEL of Web<...>: Web<...>

Which I think is because Protocol.LABEL is a class property and those were removed in 3.13.

@snarfed
Copy link
Owner

snarfed commented Feb 15, 2025

Ooh, thanks for filing! Bridgy Fed currently runs on Python 3.12, but this is useful to know.

@Daft-Freak
Copy link
Contributor Author

Blew up my local setup pretty fast, ended up working around it with this:

diff --git a/protocol.py b/protocol.py
index 25135da1..6e210b61 100644
--- a/protocol.py
+++ b/protocol.py
@@ -90,6 +90,13 @@ werkzeug.exceptions._aborter.mapping.setdefault(299, ErrorButDoNotRetryTask)
 def activity_id_memcache_key(id):
     return memcache.key(f'receive-{id}')
 
+class classproperty:
+    def __init__(self, method):
+        self.method = method
+    def __get__(self, obj, cls=None):
+        if cls is None:
+            cls = type(obj)
+        return self.method(cls)
 
 class Protocol:
     """Base protocol class. Not to be instantiated; classmethods only."""
@@ -123,8 +130,7 @@ class Protocol:
     def __init__(self):
         assert False
 
-    @classmethod
-    @property
+    @classproperty
     def LABEL(cls):
         """str: human-readable lower case name of this protocol, eg ``'activitypub``"""
         return cls.__name__.lower()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants