Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue3135

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:inspect.getcallargs()
Type:enhancementStage:
Components:Library (Lib)Versions:Python 2.7
process
Status:closedResolution:accepted
Dependencies:Superseder:
Assigned To:Nosy List: Alexander.Belopolsky, benjamin.peterson, gsakkis
Priority:normalKeywords:patch

Created on2008-06-18 22:16 bygsakkis, last changed2022-04-11 14:56 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
getcallargs.patchgsakkis,2010-03-19 13:22
getcallargs2.patchgsakkis,2010-03-19 18:12
Messages (10)
msg68378 -(view)Author: George Sakkis (gsakkis)Date: 2008-06-18 22:16
I'd like to propose a new function for inclusion to the inspect module-- getcallargs(func, *args, **kwds) -- that returns a dict which mapsthe formal arguments of a function (or other callable) to the valuespassed as args and kwds, just as Python has to do when callingfunc(*args, **kwds). For example:>>> def func(a, b='foo', c=None, *x, **y):...         pass>>> sorted(getcallargs(func, 5, z=3, b=2).items()) [('a', 5), ('b', 2), ('c', None), ('x', ()), ('y', {'z': 3})]This is handy when writing decorators, or more generally when one wouldwant to do some minimal type checking without actually calling the function.I have posted a recipe athttp://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/551779; I canclean it up and submit a proper patch if it's deemed useful enough forthe stdlib.
msg87787 -(view)Author: George Sakkis (gsakkis)Date: 2009-05-15 01:46
I updated the recipe to also return a `missing_args` tuple - the tupleof the formal parameters whose value was not provided. This is useful incases where one want to distinguish f() from f(None) given "def f(x=None)".
msg87788 -(view)Author: George Sakkis (gsakkis)Date: 2009-05-15 01:47
Also updated url:http://code.activestate.com/recipes/551779/
msg101303 -(view)Author: George Sakkis (gsakkis)Date: 2010-03-19 03:30
I reverted the function to the original API (return just the dict with the bindings), cleaned it up, wrote thorough unit tests and made a patch against Python 2.7a4.
msg101326 -(view)Author: George Sakkis (gsakkis)Date: 2010-03-19 13:22
Renamed the Testcase classes to conform with the rest in test_inspect.py, added a few more tests for tuple args and patched against the latest trunk (r79086).
msg101327 -(view)Author: Benjamin Peterson (benjamin.peterson)*(Python committer)Date: 2010-03-19 13:50
The patch will also need docs in inspect.rst.
msg101339 -(view)Author: George Sakkis (gsakkis)Date: 2010-03-19 18:12
- Added docs in inspect.rst- Fixed TypeError message for zero-arg functions ("takes no arguments" instead of "takes exactly 0 arguments") + added test.
msg101341 -(view)Author: Benjamin Peterson (benjamin.peterson)*(Python committer)Date: 2010-03-19 21:34
Would you upload this patch to Rietveld for review?
msg101348 -(view)Author: George Sakkis (gsakkis)Date: 2010-03-19 22:31
Uploaded athttp://codereview.appspot.com/659041/show
msg101951 -(view)Author: Benjamin Peterson (benjamin.peterson)*(Python committer)Date: 2010-03-30 17:59
Applied inr79500. Note I removed the error checking that a bound method received an instance of the class as the first argument because that error checking is a function of the calling of the function, not the binding of the arguments.
History
DateUserActionArgs
2022-04-11 14:56:35adminsetgithub: 47385
2010-03-30 17:59:44benjamin.petersonsetstatus: open -> closed
resolution: accepted
messages: +msg101951
2010-03-19 22:31:13gsakkissetmessages: +msg101348
2010-03-19 21:34:47benjamin.petersonsetmessages: +msg101341
2010-03-19 18:12:56gsakkissetfiles: +getcallargs2.patch

messages: +msg101339
2010-03-19 13:50:59benjamin.petersonsetnosy: +benjamin.peterson
messages: +msg101327
2010-03-19 13:22:55gsakkissetfiles: +getcallargs.patch

messages: +msg101326
2010-03-19 13:20:33gsakkissetfiles: -getcallargs.patch
2010-03-19 05:05:33Alexander.Belopolskysetnosy: +Alexander.Belopolsky
2010-03-19 03:30:31gsakkissetfiles: +getcallargs.patch
keywords: +patch
messages: +msg101303
2009-05-15 01:47:40gsakkissetmessages: +msg87788
2009-05-15 01:46:39gsakkissetmessages: +msg87787
versions: + Python 2.7, - Python 2.6
2008-06-18 22:16:53gsakkiscreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp