Consider deprecating a bunch of `inspect` functions

We have multiple APIs related to callables and signatures in inspect. Some of them even documented to exist only to match Python2 behavior. Plus, using some of them can lead to potential errors.

Separate issues: I suspect the same would be true of any stdlib code using either getargs or getfullargspec. We should probably deprecate and remove getargs and maybe eventually getfullargspec.

Originally suggested by @tjreedy

Problems

While working on `turtle.teleport` has incorrect-ish signature · Issue #107805 · python/cpython · GitHub I’ve noticed that inspect.getargs does not correctly handle:

  1. pos-only params
  2. kw-only params
  3. some defaults
  4. annotations

This was leading to a bug in callable generation, because some kw-only params were implicitly translated into regular ones.

List of functions to deprecate

So, I’ve strated looking into inspect’s API closer. Here’s a list of things that I find problematic:

Code search

Internal:

All of these functions are used in the 3rd party projects:

Proposal

I propose to:

  1. Provide modern alternatives to getargs and getargvalues
  2. Deprecating these 4 functions above with a DeprecationWarning in 3.13 with no particular removal date

I can send PRs with new functions and deprecations, if we agree on this.

Please, share your feedback.

4 Likes

The important thing is having modern fully capable alternatives in place that can satisfy the needs of users of the existing APIs. Without that, deprecating these only causes pain as no functional alternatives exist. So overall, agreed: Succeed in doing #1 (modern alternatives) and #2 (open ended deprecation) can actually be started.

3 Likes

It is also worth considering if the replacement can be done such that it is usable Python 3.8-3.12 as a PyPI package so that existing users of the APIs could go ahead and move off everywhere.

1 Like

inspect.signature() is available since Python 3.3. Is it hard to migrate existing code to inspect.signature()? Would documentation and/or tooling help migrating?

1 Like

GH issue: Add modern alternatives to `inspect` module, deprecate old incorrect APIs · Issue #108901 · python/cpython · GitHub