
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2008-06-18 22:16 bygsakkis, last changed2022-04-11 14:56 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| getcallargs.patch | gsakkis,2010-03-19 13:22 | |||
| getcallargs2.patch | gsakkis,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)*![]() | 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)*![]() | 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)*![]() | 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 | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:35 | admin | set | github: 47385 |
| 2010-03-30 17:59:44 | benjamin.peterson | set | status: open -> closed resolution: accepted messages: +msg101951 |
| 2010-03-19 22:31:13 | gsakkis | set | messages: +msg101348 |
| 2010-03-19 21:34:47 | benjamin.peterson | set | messages: +msg101341 |
| 2010-03-19 18:12:56 | gsakkis | set | files: +getcallargs2.patch messages: +msg101339 |
| 2010-03-19 13:50:59 | benjamin.peterson | set | nosy: +benjamin.peterson messages: +msg101327 |
| 2010-03-19 13:22:55 | gsakkis | set | files: +getcallargs.patch messages: +msg101326 |
| 2010-03-19 13:20:33 | gsakkis | set | files: -getcallargs.patch |
| 2010-03-19 05:05:33 | Alexander.Belopolsky | set | nosy: +Alexander.Belopolsky |
| 2010-03-19 03:30:31 | gsakkis | set | files: +getcallargs.patch keywords: +patch messages: +msg101303 |
| 2009-05-15 01:47:40 | gsakkis | set | messages: +msg87788 |
| 2009-05-15 01:46:39 | gsakkis | set | messages: +msg87787 versions: + Python 2.7, - Python 2.6 |
| 2008-06-18 22:16:53 | gsakkis | create | |