Changeset 391 for python/trunk/Doc/library/inspect.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/inspect.rst
r2 r391 1 2 1 :mod:`inspect` --- Inspect live objects 3 2 ======================================= … … 10 9 11 10 .. versionadded:: 2.1 11 12 **Source code:** :source:`Lib/inspect.py` 13 14 -------------- 12 15 13 16 The :mod:`inspect` module provides several useful functions to help get … … 235 238 Return a tuple of values that describe how Python will interpret the file 236 239 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 enclosing239 package, *suffix* is the trailing part of the file name (which may not be a240 dot-delimited extension), *mode* is the :func:`open` mode that would be used241 (``'r'`` or ``'rb'``), and *mtype* is an integer giving the type of the242 module. *mtype* will have a value which can be compared to the constants243 defined in the :mod:`imp` module; see the documentation for that module for244 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. 245 248 246 249 .. versionchanged:: 2.6 … … 264 267 .. function:: isclass(object) 265 268 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. 267 271 268 272 269 273 .. function:: ismethod(object) 270 274 271 Return true if the object is a method.275 Return true if the object is a bound method written in Python. 272 276 273 277 274 278 .. function:: isfunction(object) 275 279 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 277 283 278 284 .. function:: isgeneratorfunction(object) … … 282 288 .. versionadded:: 2.6 283 289 290 284 291 .. function:: isgenerator(object) 285 292 … … 288 295 .. versionadded:: 2.6 289 296 297 290 298 .. function:: istraceback(object) 291 299 … … 305 313 .. function:: isbuiltin(object) 306 314 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. 308 316 309 317 … … 312 320 Return true if the object is a user-defined or built-in function or method. 313 321 322 314 323 .. function:: isabstract(object) 315 324 … … 321 330 .. function:: ismethoddescriptor(object) 322 331 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. 325 335 326 336 This is new as of Python 2.2, and, for example, is true of … … 357 367 358 368 getsets are attributes defined in extension modules via 359 :c type:`PyGetSetDef` structures. For Python implementations without such369 :c:type:`PyGetSetDef` structures. For Python implementations without such 360 370 types, this method will always return ``False``. 361 371 … … 370 380 371 381 Member descriptors are attributes defined in extension modules via 372 :c type:`PyMemberDef` structures. For Python implementations without such382 :c:type:`PyMemberDef` structures. For Python implementations without such 373 383 types, this method will always return ``False``. 374 384 … … 458 468 .. function:: getargspec(func) 459 469 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*. 466 477 467 478 .. versionchanged:: 2.6 … … 472 483 .. function:: getargvalues(frame) 473 484 474 Get information about arguments passed into a particular frame. A tuple of four475 things is returned: ``(args, varargs, varkw, locals)``. *args* is a list of the476 argument names (it may contain nested lists). *varargs* and *varkw* are the477 names of the ``*`` and ``**`` arguments or ``None``. *locals* is the locals478 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. 479 490 480 491 .. versionchanged:: 2.6 … … 503 514 resolution order depends on cls's type. Unless a very peculiar user-defined 504 515 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 505 542 506 543
Note:
See TracChangeset
for help on using the changeset viewer.