| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -872,6 +872,16 @@ Using the non-data descriptor protocol, a pure Python version of | |||
| 872 | 872 | def __get__(self, obj, cls=None): | |
| 873 | 873 | if cls is None: | |
| 874 | 874 | cls = type(obj) | |
| 875 | - def newfunc(*args): | ||
| 876 | - return self.f(cls, *args) | ||
| 877 | - return newfunc | ||
| 875 | + if hasattr(obj, '__get__'): | ||
| 876 | + return self.f.__get__(cls) | ||
| 877 | + return types.MethodType(self.f, cls) | ||
| 878 | + | ||
| 879 | + The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and | ||
| 880 | + makes it possible for :func:`classmethod` to support chained decorators. | ||
| 881 | + For example, a classmethod and property could be chained together:: | ||
| 882 | + | ||
| 883 | + class G: | ||
| 884 | + @classmethod | ||
| 885 | + @property | ||
| 886 | + def __doc__(cls): | ||
| 887 | + return f'A doc for {cls.__name__!r}' | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments