This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients Viktor Roytman, levkivskyi, lukasz.langa, ncoghlan, xtreak
Date 2020-02-19.05:36:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582090576.86.0.973261276625.issue39679@roundup.psfhosted.org>
In-reply-to
Content
I guess the method checks for annotation on cls [0] which will be classmethod/staticmethod object in the report and won't have annotations. The annotations should be looked up in the function the classmethod/staticmethod decorator wraps around as in cls.__func__ . Something like below so that the right annotations are picked up. In addition to this the registry should store the type annotation as key to cls or cls.__func__ depending on normal method or classmethod/staticmethod.

diff --git Lib/functools.py Lib/functools.py
index 050bec8605..a66711208d 100644
--- Lib/functools.py
+++ Lib/functools.py
@@ -1073,24 +1073,33 @@ def singledispatch(func):
         if func is None:
             if isinstance(cls, type):
                 return lambda f: register(cls, f)
-            ann = getattr(cls, '__annotations__', {})
+            if isinstance(cls, (classmethod, staticmethod)):
+                ann = getattr(cls.__func__, '__annotations__', {})
+                func = cls.__func__
+            else:
+                ann = getattr(cls, '__annotations__', {})
+                func = cls

[0] https://github.com/python/cpython/blob/ab6423fe2de0ed5f8a0dc86a9c7070229326b0f0/Lib/functools.py#L1076
History
Date User Action Args
2020-02-19 05:36:16xtreaksetrecipients: + xtreak, ncoghlan, lukasz.langa, levkivskyi, Viktor Roytman
2020-02-19 05:36:16xtreaksetmessageid: <1582090576.86.0.973261276625.issue39679@roundup.psfhosted.org>
2020-02-19 05:36:16xtreaklinkissue39679 messages
2020-02-19 05:36:16xtreakcreate