This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add example for inspect module doc
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, belopolsky, berker.peksag, docs@python, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2012-10-15 23:19 by belopolsky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
inspect-formatargspec-example.patch berker.peksag, 2012-10-25 21:44 review
Messages (6)
msg173003 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-10-15 23:19
In Python 3.3.0 and 3.2.3:

>>> from inspect import *
>>> def f(a,b):pass
...
>>> formatargspec(getargspec(f))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/inspect.py", line 905, in formatargspec
    spec = formatargandannotation(arg)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/inspect.py", line 898, in formatargandannotation
    if arg in annotations:
TypeError: unhashable type: 'list'

No such error in 2.7.1:

>>> formatargspec(getargspec(f))
'((a, b), None, None, None)'
msg173004 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-10-15 23:57
It looks like a typo in your code. You should use instead:
formatargspec(*getargspec(f))

Or better:
formatargspec(*getfullargspec(f))

Try with:
def f(a: int, b: float): pass
msg173010 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-10-16 02:30
My bad, but I think documentation can be improved by adding an example.
msg173802 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-10-25 21:44
Here's a patch that adds an example of using `inspect.formatargspec`.
msg173892 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-26 21:28
New changeset 9d3b616fc702 by Andrew Svetlov in branch '3.3':
Issue #16243: add example for inspect.formatargspec
http://hg.python.org/cpython/rev/9d3b616fc702

New changeset a0337031a6b7 by Andrew Svetlov in branch 'default':
Merge issue #16243: add example for inspect.formatargspec
http://hg.python.org/cpython/rev/a0337031a6b7
msg173893 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-10-26 21:31
Thanks, Berker.
I feel the patch is good enough to close the issue.
If anybody want to add some value please reopen.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60447
2012-10-26 21:31:00asvetlovsetstatus: open -> closed

nosy: + asvetlov
messages: + msg173893

resolution: fixed
stage: resolved
2012-10-26 21:28:59python-devsetnosy: + python-dev
messages: + msg173892
2012-10-25 21:44:02berker.peksagsetfiles: + inspect-formatargspec-example.patch

nosy: + berker.peksag
messages: + msg173802

keywords: + patch
2012-10-19 18:47:00terry.reedysettitle: Regression in inspect module -> Add example for inspect module doc
2012-10-16 02:30:50belopolskysetassignee: docs@python
type: behavior -> enhancement
components: + Documentation, - Library (Lib)
versions: - Python 3.2, Python 3.3
nosy: + docs@python

messages: + msg173010
2012-10-15 23:57:54vstinnersetnosy: + vstinner
messages: + msg173004
2012-10-15 23:19:45belopolskycreate