classification
Title: inspecting a partial with bound keywords gives incorrect signature
Type: Stage:
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ido Michael, cjw296, donovick
Priority: normal Keywords:

Created on 2020-02-25 18:42 by cjw296, last changed 2020-03-02 07:30 by cjw296.

Messages (4)
msg362656 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2020-02-25 18:42
$ python
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from functools import partial
>>> def foo(x, y, z, a=None): pass
... 
>>> p = partial(foo, 1, y=2)
>>> from inspect import signature
>>> signature(p).parameters.values()
odict_values([<Parameter "y=2">, <Parameter "z">, <Parameter "a=None">])

That <Parameter "y=2"> shouldn't be in there:

>>> p(2, y=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for argument 'y'
msg362657 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2020-02-25 18:44
Surprised partials have no explicit signature:

>>> p.__signature__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'functools.partial' object has no attribute '__signature__'
msg363084 - (view) Author: Ido Michael (Ido Michael) * Date: 2020-03-01 19:40
Is it a bug? I can add the signature and set a PR
msg363132 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2020-03-02 07:30
Not sure I understand your comment.

The results of calling inpsect on a partial with bound keyword parameters are incorrect. Furthermore, it is surprisingly that partial objects don't maintain their own __signature__.

What is it you're suggesting?
History
Date User Action Args
2020-03-02 07:30:17cjw296setmessages: + msg363132
title: inspecting a partial with bound keywods gives incorrect signature -> inspecting a partial with bound keywords gives incorrect signature
2020-03-01 19:40:59Ido Michaelsetnosy: + Ido Michael
messages: + msg363084
2020-02-28 02:30:33donovicksetnosy: + donovick
2020-02-25 18:44:58cjw296setmessages: + msg362657
2020-02-25 18:42:45cjw296setcomponents: + Library (Lib)
versions: + Python 3.8
2020-02-25 18:42:14cjw296create