Skip to content
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

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

Closed
jcea opened this issue Nov 17, 2012 · 11 comments
Closed

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

jcea opened this issue Nov 17, 2012 · 11 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@jcea
Copy link
Member

jcea commented Nov 17, 2012

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']

@jcea
Copy link
Member Author

jcea commented Nov 17, 2012

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?

@jcea jcea changed the title "inspect.getargspec()" and "inspect.getcallargs()" don't work with builtins "inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins Nov 17, 2012
@jcea jcea added the type-feature A feature request or enhancement label Nov 17, 2012
@jcea
Copy link
Member Author

jcea commented Nov 17, 2012

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.

@brettcannon
Copy link
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.

@larryhastings
Copy link
Contributor

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

@larryhastings larryhastings self-assigned this Nov 17, 2012
@jcea
Copy link
Member Author

jcea commented Nov 30, 2012

Larry, Ping... :-)

@larryhastings
Copy link
Contributor

@davidvilla
Copy link
Mannequin

davidvilla mannequin commented Dec 4, 2012

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

@jcea
Copy link
Member Author

jcea commented Dec 6, 2012

David, please subscribe to Issue bpo-16612.

@berkerpeksag
Copy link
Member

This looks like a duplicate of bpo-1748064.

@1st1
Copy link
Member

1st1 commented Jan 11, 2014

This is related to issue bpo-17481

@1st1
Copy link
Member

1st1 commented Jan 27, 2014

Closing this issue. See bpo-17481 for details.

@1st1 1st1 closed this as completed Jan 27, 2014
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants