Skip to content

inspect.getcallargs() #47385

Closed
Closed

Description

@gsakkis
mannequin
BPO 3135
Nosy @benjaminp
Files
  • getcallargs.patch
  • getcallargs2.patch
  • 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 = None
    closed_at = <Date 2010-03-30.17:59:44.555>
    created_at = <Date 2008-06-18.22:16:52.950>
    labels = ['type-feature', 'library']
    title = 'inspect.getcallargs()'
    updated_at = <Date 2010-03-30.17:59:44.553>
    user = 'https://bugs.python.org/gsakkis'

    bugs.python.org fields:

    activity = <Date 2010-03-30.17:59:44.553>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-03-30.17:59:44.555>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-06-18.22:16:52.950>
    creator = 'gsakkis'
    dependencies = []
    files = ['16587', '16591']
    hgrepos = []
    issue_num = 3135
    keywords = ['patch']
    message_count = 10.0
    messages = ['68378', '87787', '87788', '101303', '101326', '101327', '101339', '101341', '101348', '101951']
    nosy_count = 3.0
    nosy_names = ['gsakkis', 'benjamin.peterson', 'Alexander.Belopolsky']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3135'
    versions = ['Python 2.7']

    Activity

    1. gsakkis commented on Jun 18, 2008

      gsakkismannequin
      MannequinAuthor

      I'd like to propose a new function for inclusion to the inspect module
      -- getcallargs(func, *args, **kwds) -- that returns a dict which maps
      the formal arguments of a function (or other callable) to the values
      passed as args and kwds, just as Python has to do when calling
      func(*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 would
      want to do some minimal type checking without actually calling the function.

      I have posted a recipe at
      http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/551779; I can
      clean it up and submit a proper patch if it's deemed useful enough for
      the stdlib.

    2. added
      stdlib
      type-feature
      on Jun 18, 2008
    3. gsakkis commented on May 15, 2009

      gsakkismannequin
      MannequinAuthor

      I updated the recipe to also return a missing_args tuple - the tuple
      of the formal parameters whose value was not provided. This is useful in
      cases where one want to distinguish f() from f(None) given "def f(x=None)".

    4. gsakkis commented on May 15, 2009

      gsakkismannequin
      MannequinAuthor
    5. gsakkis commented on Mar 19, 2010

      gsakkismannequin
      MannequinAuthor

      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.

    6. gsakkis commented on Mar 19, 2010

      gsakkismannequin
      MannequinAuthor

      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).

    7. benjaminp commented on Mar 19, 2010

      @benjaminp
      Contributor

      The patch will also need docs in inspect.rst.

    8. gsakkis commented on Mar 19, 2010

      gsakkismannequin
      MannequinAuthor
      • Added docs in inspect.rst
      • Fixed TypeError message for zero-arg functions ("takes no arguments" instead of "takes exactly 0 arguments") + added test.
    9. benjaminp commented on Mar 19, 2010

      @benjaminp
      Contributor

      Would you upload this patch to Rietveld for review?

    10. gsakkis commented on Mar 19, 2010

      gsakkismannequin
      MannequinAuthor
    11. benjaminp commented on Mar 30, 2010

      @benjaminp
      Contributor

      Applied in r79500. 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.

    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

    No one assigned

      Labels

      stdlibtype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions