Skip to content

"inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins #60694

Closed

Description

@jcea
BPO 16490
Nosy @brettcannon, @jcea, @larryhastings, @asvetlov, @berkerpeksag, @1st1

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/larryhastings'
closed_at = <Date 2014-01-27.20:34:56.195>
created_at = <Date 2012-11-17.03:36:29.421>
labels = ['type-feature']
title = '"inspect.getargspec()" and "inspect.getcallargs()" don\'t work for builtins'
updated_at = <Date 2014-01-27.20:34:56.194>
user = 'https://github.com/jcea'

bugs.python.org fields:

activity = <Date 2014-01-27.20:34:56.194>
actor = 'yselivanov'
assignee = 'larry'
closed = True
closed_date = <Date 2014-01-27.20:34:56.195>
closer = 'yselivanov'
components = []
creation = <Date 2012-11-17.03:36:29.421>
creator = 'jcea'
dependencies = []
files = []
hgrepos = []
issue_num = 16490
keywords = []
message_count = 11.0
messages = ['175725', '175726', '175745', '175752', '176693', '176867', '176878', '177022', '177221', '207922', '209475']
nosy_count = 7.0
nosy_names = ['brett.cannon', 'jcea', 'larry', 'asvetlov', 'berker.peksag', 'yselivanov', 'david.villa']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue16490'
versions = ['Python 3.4']

Activity

  1. jcea commented on Nov 17, 2012

    @jcea
    MemberAuthor

    Yesterday I was attending a conference about a MOCK like library and the speaker told us about some "inspect" functionalities not working correctly with builtins. For instance:

    """
    Python 3.3.0 (default, Oct  2 2012, 02:07:16) 
    [GCC 4.4.3] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import inspect
    >>> def f(a=None) :
    ...   pass
    ... 
    >>> inspect.getcallargs(f)
    {'a': None}
    >>> inspect.getargspec(f)
    ArgSpec(args=['a'], varargs=None, keywords=None, defaults=(None,))
    >>> inspect.getcallargs(list)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.3/inspect.py", line 993, in getcallargs
        spec = getfullargspec(func)
      File "/usr/local/lib/python3.3/inspect.py", line 850, in getfullargspec
        raise TypeError('{!r} is not a Python function'.format(func))
    TypeError: <class 'list'> is not a Python function
    >>> inspect.getargspec(list)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.3/inspect.py", line 823, in getargspec
        getfullargspec(func)
      File "/usr/local/lib/python3.3/inspect.py", line 850, in getfullargspec
        raise TypeError('{!r} is not a Python function'.format(func))
    TypeError: <class 'list'> is not a Python function
    >>> 
    """

    Can we annotate builtins to support this?. What about types defined in CModules?

  2. changed the title [-]"inspect.getargspec()" and "inspect.getcallargs()" don't work with builtins[/-] [+]"inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins[/+] on Nov 17, 2012
  3. jcea commented on Nov 17, 2012

    @jcea
    MemberAuthor

    I am fully aware that the interpreter doesn't know how a method/function written in C is going to parse the parameter list/keywords. And that even if we solve this (for instance, with annotations that create wrappers calling "PyArg_Parse()" automatically), every C extension out there would need to support it too.

    Just brainstorming.

  4. brettcannon commented on Nov 17, 2012

    @brettcannon
    Member

    So at this point you should use inspect.signature(), not getfullargspec().

    With that you could do this if you either allowed setting the __signature__ attribute and then provided code that would set it, made __signature__ a property that returned the Signature object if desired on a built-in, or come up with some automated way to take the argument string from PyArg_Parse() as you suggested.

  5. larryhastings commented on Nov 17, 2012

    @larryhastings
    Contributor

    I'm working on a solution for this--expect an announcement on c.l.p-d in, oh, a week.

  6. jcea commented on Nov 30, 2012

    @jcea
    MemberAuthor

    Larry, Ping... :-)

  7. davidvilla commented on Dec 4, 2012

    davidvillamannequin
    Mannequin

    What about something like gobject.introspection?
    https://live.gnome.org/GObjectIntrospection/

  8. jcea commented on Dec 6, 2012

    @jcea
    MemberAuthor

    David, please subscribe to Issue bpo-16612.

  9. berkerpeksag commented on Dec 9, 2012

    @berkerpeksag
    Member

    This looks like a duplicate of bpo-1748064.

  10. 1st1 commented on Jan 11, 2014

    @1st1
    Member

    This is related to issue bpo-17481

  11. 1st1 commented on Jan 27, 2014

    @1st1
    Member

    Closing this issue. See bpo-17481 for details.

  12. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions