]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127750: Fix functools.singledispatchmethod() (GH-130029)
authorPieter Eendebak <pieter.eendebak@gmail.com>
Mon, 17 Feb 2025 09:12:24 +0000 (10:12 +0100)
committerGitHub <noreply@github.com>
Mon, 17 Feb 2025 09:12:24 +0000 (11:12 +0200)
Revert gh-107148

Lib/functools.py
Misc/NEWS.d/next/Library/2025-02-12-09-48-25.gh-issue-127750.ibhIZg.rst [new file with mode: 0644]

index 2bc5053bd1b53f90c4c7963024d3f0d45ddb05b0..4c1175b815d6ecd7dc0e1ca9d1d302d183781261 100644 (file)
@@ -958,9 +958,6 @@ class singledispatchmethod:
         self.dispatcher = singledispatch(func)
         self.func = func
 
-        import weakref # see comment in singledispatch function
-        self._method_cache = weakref.WeakKeyDictionary()
-
     def register(self, cls, method=None):
         """generic_method.register(cls, func) -> func
 
@@ -969,16 +966,6 @@ class singledispatchmethod:
         return self.dispatcher.register(cls, func=method)
 
     def __get__(self, obj, cls=None):
-        if self._method_cache is not None:
-            try:
-                _method = self._method_cache[obj]
-            except TypeError:
-                self._method_cache = None
-            except KeyError:
-                pass
-            else:
-                return _method
-
         dispatch = self.dispatcher.dispatch
         funcname = getattr(self.func, '__name__', 'singledispatchmethod method')
         def _method(*args, **kwargs):
@@ -991,9 +978,6 @@ class singledispatchmethod:
         _method.register = self.register
         update_wrapper(_method, self.func)
 
-        if self._method_cache is not None:
-            self._method_cache[obj] = _method
-
         return _method
 
     @property
diff --git a/Misc/NEWS.d/next/Library/2025-02-12-09-48-25.gh-issue-127750.ibhIZg.rst b/Misc/NEWS.d/next/Library/2025-02-12-09-48-25.gh-issue-127750.ibhIZg.rst
new file mode 100644 (file)
index 0000000..a828054
--- /dev/null
@@ -0,0 +1,2 @@
+Remove broken :func:`functools.singledispatchmethod` caching introduced in\r
+:gh:`85160`.