bpo-36743: __get__ is sometimes called without the owner argument (GH-12992) (GH-15589)
(cherry picked from commit 0dac68f1e593c11612ed54af9edb865d398f3b05)
Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 6501092..eb4e662 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -281,7 +281,7 @@
class DocDescriptor:
"""Helper for builtins.open.__doc__
"""
- def __get__(self, obj, typ):
+ def __get__(self, obj, typ=None):
return (
"open(file, mode='r', buffering=-1, encoding=None, "
"errors=None, newline=None, closefd=True)\n\n" +
diff --git a/Lib/functools.py b/Lib/functools.py
index 64d1201..a674a68 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -400,7 +400,7 @@
_method._partialmethod = self
return _method
- def __get__(self, obj, cls):
+ def __get__(self, obj, cls=None):
get = getattr(self.func, "__get__", None)
result = None
if get is not None:
@@ -905,7 +905,7 @@
"""
return self.dispatcher.register(cls, func=method)
- def __get__(self, obj, cls):
+ def __get__(self, obj, cls=None):
def _method(*args, **kwargs):
method = self.dispatcher.dispatch(args[0].__class__)
return method.__get__(obj, cls)(*args, **kwargs)
@@ -943,7 +943,7 @@
f"({self.attrname!r} and {name!r})."
)
- def __get__(self, instance, owner):
+ def __get__(self, instance, owner=None):
if instance is None:
return self
if self.attrname is None:
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 7ab6812..4c76f53 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2806,7 +2806,7 @@
def _get_child_mock(self, /, **kwargs):
return MagicMock(**kwargs)
- def __get__(self, obj, obj_type):
+ def __get__(self, obj, obj_type=None):
return self()
def __set__(self, obj, val):
self(val)