8000 bpo-38364: unwrap partialmethods just like we unwrap partials by mjpieters · Pull Request #16600 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38364: unwrap partialmethods just like we unwrap partials #16600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rename _partialmethod to __partialmethod__
Since we'rs checking this attribute on arbitrary function-like objects,
we should use the namespace reserved for core Python.
  • Loading branch information
encukou committed Jan 25, 2024
commit fa36941d38b6d87ddb7715116f85a78254403028
6 changes: 3 additions & 3 deletions Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def _method(cls_or_self, /, *args, **keywords):
keywords = {**self.keywords, **keywords}
return self.func(cls_or_self, *self.args, *args, **keywords)
_method.__isabstractmethod__ = self.__isabstractmethod__
_method._partialmethod = self
_method.__partialmethod__ = self
return _method

def __get__(self, obj, cls=None):
Expand Down Expand Up @@ -428,8 +428,8 @@ def _unwrap_partialmethod(func):
prev = None
while func is not prev:
prev = func
while isinstance(getattr(func, "_partialmethod", None), partialmethod):
func = func._partialmethod
while isinstance(getattr(func, "__partialmethod__", None), partialmethod):
func = func.__partialmethod__
while isinstance(func, partialmethod):
func = getattr(func, 'func')
func = _unwrap_partial(func)
Expand Down
2 changes: 1 addition & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ def _signature_from_callable(obj, *,
return sig

try:
partialmethod = obj._partialmethod
partialmethod = obj.__partialmethod__
except AttributeError:
pass
else:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,7 @@ def test(self: 'anno', x):

def test_signature_on_fake_partialmethod(self):
def foo(a): pass
foo._partialmethod = 'spam'
foo.__partialmethod__ = 'spam'
self.assertEqual(str(inspect.signature(foo)), '(a)')

def test_signature_on_decorated(self):
Expand Down
0