diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-06-27 11:47:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 11:47:20 (GMT) |
commit | db96edd6d1a58045196a71aff565743f493b5fbb (patch) | |
tree | eea2596651c3e0b059363e014624eafd28ad5896 /Lib/functools.py | |
parent | 223c03a43c010cf4404f2a42efafe587646a0619 (diff) | |
download | cpython-db96edd6d1a58045196a71aff565743f493b5fbb.zip cpython-db96edd6d1a58045196a71aff565743f493b5fbb.tar.gz cpython-db96edd6d1a58045196a71aff565743f493b5fbb.tar.bz2 |
gh-121027: Add a future warning in functools.partial.__get__ (#121086)
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index 3d0fd66..d04957c 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -311,6 +311,16 @@ class partial: args.extend(f"{k}={v!r}" for (k, v) in self.keywords.items()) return f"{module}.{qualname}({', '.join(args)})" + def __get__(self, obj, objtype=None): + if obj is None: + return self + import warnings + warnings.warn('functools.partial will be a method descriptor in ' + 'future Python versions; wrap it in staticmethod() ' + 'if you want to preserve the old behavior', + FutureWarning, 2) + return self + def __reduce__(self): return type(self), (self.func,), (self.func, self.args, self.keywords or None, self.__dict__ or None) @@ -392,7 +402,7 @@ class partialmethod(object): def __get__(self, obj, cls=None): get = getattr(self.func, "__get__", None) result = None - if get is not None: + if get is not None and not isinstance(self.func, partial): new_func = get(obj, cls) if new_func is not self.func: # Assume __get__ returning something new indicates the |