Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/inspect.rst

    r2 r391  
    1 
    21:mod:`inspect` --- Inspect live objects
    32=======================================
     
    109
    1110.. versionadded:: 2.1
     11
     12**Source code:** :source:`Lib/inspect.py`
     13
     14--------------
    1215
    1316The :mod:`inspect` module provides several useful functions to help get
     
    235238   Return a tuple of values that describe how Python will interpret the file
    236239   identified by *path* if it is a module, or ``None`` if it would not be
    237    identified as a module.  The return tuple is ``(name, suffix, mode, mtype)``,
    238    where *name* is the name of the module without the name of any enclosing
    239    package, *suffix* is the trailing part of the file name (which may not be a
    240    dot-delimited extension), *mode* is the :func:`open` mode that would be used
    241    (``'r'`` or ``'rb'``), and *mtype* is an integer giving the type of the
    242    module.  *mtype* will have a value which can be compared to the constants
    243    defined in the :mod:`imp` module; see the documentation for that module for
    244    more information on module types.
     240   identified as a module.  The return tuple is ``(name, suffix, mode,
     241   module_type)``, where *name* is the name of the module without the name of
     242   any enclosing package, *suffix* is the trailing part of the file name (which
     243   may not be a dot-delimited extension), *mode* is the :func:`open` mode that
     244   would be used (``'r'`` or ``'rb'``), and *module_type* is an integer giving
     245   the type of the module.  *module_type* will have a value which can be
     246   compared to the constants defined in the :mod:`imp` module; see the
     247   documentation for that module for more information on module types.
    245248
    246249   .. versionchanged:: 2.6
     
    264267.. function:: isclass(object)
    265268
    266    Return true if the object is a class.
     269   Return true if the object is a class, whether built-in or created in Python
     270   code.
    267271
    268272
    269273.. function:: ismethod(object)
    270274
    271    Return true if the object is a method.
     275   Return true if the object is a bound method written in Python.
    272276
    273277
    274278.. function:: isfunction(object)
    275279
    276    Return true if the object is a Python function or unnamed (:term:`lambda`) function.
     280   Return true if the object is a Python function, which includes functions
     281   created by a :term:`lambda` expression.
     282
    277283
    278284.. function:: isgeneratorfunction(object)
     
    282288   .. versionadded:: 2.6
    283289
     290
    284291.. function:: isgenerator(object)
    285292
     
    288295   .. versionadded:: 2.6
    289296
     297
    290298.. function:: istraceback(object)
    291299
     
    305313.. function:: isbuiltin(object)
    306314
    307    Return true if the object is a built-in function.
     315   Return true if the object is a built-in function or a bound built-in method.
    308316
    309317
     
    312320   Return true if the object is a user-defined or built-in function or method.
    313321
     322
    314323.. function:: isabstract(object)
    315324
     
    321330.. function:: ismethoddescriptor(object)
    322331
    323    Return true if the object is a method descriptor, but not if :func:`ismethod`
    324    or :func:`isclass` or :func:`isfunction` are true.
     332   Return true if the object is a method descriptor, but not if
     333   :func:`ismethod`, :func:`isclass`, :func:`isfunction` or :func:`isbuiltin`
     334   are true.
    325335
    326336   This is new as of Python 2.2, and, for example, is true of
     
    357367
    358368      getsets are attributes defined in extension modules via
    359       :ctype:`PyGetSetDef` structures.  For Python implementations without such
     369      :c:type:`PyGetSetDef` structures.  For Python implementations without such
    360370      types, this method will always return ``False``.
    361371
     
    370380
    371381      Member descriptors are attributes defined in extension modules via
    372       :ctype:`PyMemberDef` structures.  For Python implementations without such
     382      :c:type:`PyMemberDef` structures.  For Python implementations without such
    373383      types, this method will always return ``False``.
    374384
     
    458468.. function:: getargspec(func)
    459469
    460    Get the names and default values of a function's arguments. A tuple of four
    461    things is returned: ``(args, varargs, varkw, defaults)``. *args* is a list of
    462    the argument names (it may contain nested lists). *varargs* and *varkw* are the
    463    names of the ``*`` and ``**`` arguments or ``None``. *defaults* is a tuple of
    464    default argument values or None if there are no default arguments; if this tuple
    465    has *n* elements, they correspond to the last *n* elements listed in *args*.
     470   Get the names and default values of a Python function's arguments. A tuple of
     471   four things is returned: ``(args, varargs, keywords, defaults)``. *args* is a
     472   list of the argument names (it may contain nested lists). *varargs* and
     473   *keywords* are the names of the ``*`` and ``**`` arguments or
     474   ``None``. *defaults* is a tuple of default argument values or None if there
     475   are no default arguments; if this tuple has *n* elements, they correspond to
     476   the last *n* elements listed in *args*.
    466477
    467478   .. versionchanged:: 2.6
     
    472483.. function:: getargvalues(frame)
    473484
    474    Get information about arguments passed into a particular frame. A tuple of four
    475    things is returned: ``(args, varargs, varkw, locals)``. *args* is a list of the
    476    argument names (it may contain nested lists). *varargs* and *varkw* are the
    477    names of the ``*`` and ``**`` arguments or ``None``. *locals* is the locals
    478    dictionary of the given frame.
     485   Get information about arguments passed into a particular frame. A tuple of
     486   four things is returned: ``(args, varargs, keywords, locals)``. *args* is a
     487   list of the argument names (it may contain nested lists). *varargs* and
     488   *keywords* are the names of the ``*`` and ``**`` arguments or ``None``.
     489   *locals* is the locals dictionary of the given frame.
    479490
    480491   .. versionchanged:: 2.6
     
    503514   resolution order depends on cls's type.  Unless a very peculiar user-defined
    504515   metatype is in use, cls will be the first element of the tuple.
     516
     517
     518.. function:: getcallargs(func[, *args][, **kwds])
     519
     520   Bind the *args* and *kwds* to the argument names of the Python function or
     521   method *func*, as if it was called with them. For bound methods, bind also the
     522   first argument (typically named ``self``) to the associated instance. A dict
     523   is returned, mapping the argument names (including the names of the ``*`` and
     524   ``**`` arguments, if any) to their values from *args* and *kwds*. In case of
     525   invoking *func* incorrectly, i.e. whenever ``func(*args, **kwds)`` would raise
     526   an exception because of incompatible signature, an exception of the same type
     527   and the same or similar message is raised. For example::
     528
     529    >>> from inspect import getcallargs
     530    >>> def f(a, b=1, *pos, **named):
     531    ...     pass
     532    >>> getcallargs(f, 1, 2, 3)
     533    {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
     534    >>> getcallargs(f, a=2, x=4)
     535    {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
     536    >>> getcallargs(f)
     537    Traceback (most recent call last):
     538    ...
     539    TypeError: f() takes at least 1 argument (0 given)
     540
     541   .. versionadded:: 2.7
    505542
    506543
Note: See TracChangeset for help on using the changeset viewer.