X Tutup
Skip to content

gh-73536: Add support for multi-signatures#117671

Draft
serhiy-storchaka wants to merge 16 commits intopython:mainfrom
serhiy-storchaka:wip-inspect-multi-signature
Draft

gh-73536: Add support for multi-signatures#117671
serhiy-storchaka wants to merge 16 commits intopython:mainfrom
serhiy-storchaka:wip-inspect-multi-signature

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented Apr 9, 2024

  • Add inspect.MultiSignature which is a subclass of inspect.Signature.
  • Add inspect.signatures().
  • inspect.signature() can now return a multi-signature.
  • Support multi-signatures in pydoc.
  • Support multi-signatures in IDLE calltips.
  • Support multi-signatures in dataclasses docstrings.
  • Allow multiple @text_signature in Argument Clinic.
  • Add representable signatures for all builtin functions and methods of builtin classes except type() and super().

* Add inspect.MultiSignature which is a subclass of inspect.Signature.
* Add inspect.signatures().
* inspect.signature() can now return a multi-signature.
* Support multi-signatures in pydoc.
* Support multi-signatures in IDLE calltips.
* Support multi-signatures in dataclasses docstrings.
* Allow multiple @text_signature in Argument Clinic.
* Add representable signatures for all builtin functions and methods of
  builtin classes except type() and super().


def _multisignature_get_partial(wrapped_sig, partial, extra_args=()):
last_exc = None
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is checked in the constructor. I think even about removing this assignment, NameError is clearer indication if something goes wrong.

Lib/inspect.py Outdated
return True
if isinstance(other, MultiSignature):
return self._signatures == other._signatures
if len(self._signatures) == 1 and isinstance(other, Signature):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not correct, it would make a 1-element MultiSignature equal to any Signature.

You perhaps mistyped, I wrote more correct fix.


def signature(obj, *, follow_wrapped=True, globals=None, locals=None, eval_str=False):
"""Get a signature object for the passed callable."""
return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. The idea was that inspect.signature() will start to support previously not supported cases and return a MultiSignature which should be compatible with Signature. But now I am no longer sure. They are not so well compatible as I expected, and in most cases I needed to rewrite the code to explicitly handle MultiSignature. This is why I added inspect.signatures(). Now the code is in the intermediate state -- either MultiSignature will be made more compatible with Signature and inspect.signatures() may disappear, or they will became completely different things.

@skirpichev
Copy link
Copy Markdown
Member

@serhiy-storchaka, now this again has conflicts with the main. I did pr serhiy-storchaka#22 that address this, hope it helps.

Are you thinking about writing a PEP as Petr suggested?

@skirpichev
Copy link
Copy Markdown
Member

@serhiy-storchaka, will you be ok if I continue this work in a separate pr? Or you disappointed in this approach?

@merwok merwok changed the title gh-73536: Add support of multi-signatures gh-73536: Add support for multi-signatures Apr 8, 2025
dutow added a commit to dutow/conan-center-index that referenced this pull request Mar 30, 2026
Version-specific patches adapted from existing ones:

- relocatable-python-config: same change as 3.x-0001 but adjusted
  for line offset in 3.13+ python-config.sh.in (shared between
  3.13 and 3.14 since the file is identical)

- remove-module-deps: removes ProjectDependencies from the python
  project in PCbuild/pcbuild.sln (separate patches for 3.13 and
  3.14 due to different GUID sets)

- _ctypes-ffi (3.13 only): converts static formattable[] array to
  dynamic initialization for shared libffi compatibility. Not needed
  for 3.14 where this was fixed upstream by restructuring cfield.c
  into a named struct (python/cpython#117671)

The _msi-vcxproj patch is no longer needed since msilib was removed
in 3.13 per PEP 594 (python/cpython#104911).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup