/Doc/library/pyclbr.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 113 lines · 64 code · 49 blank · 0 comment · 0 complexity · a1df9676d886fb8b9e62dd8601392bc2 MD5 · raw file

  1. :mod:`pyclbr` --- Python class browser support
  2. ==============================================
  3. .. module:: pyclbr
  4. :synopsis: Supports information extraction for a Python class browser.
  5. .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
  6. The :mod:`pyclbr` module can be used to determine some limited information
  7. about the classes, methods and top-level functions defined in a module. The
  8. information provided is sufficient to implement a traditional three-pane
  9. class browser. The information is extracted from the source code rather
  10. than by importing the module, so this module is safe to use with untrusted
  11. code. This restriction makes it impossible to use this module with modules
  12. not implemented in Python, including all standard and optional extension
  13. modules.
  14. .. function:: readmodule(module[, path=None])
  15. Read a module and return a dictionary mapping class names to class
  16. descriptor objects. The parameter *module* should be the name of a
  17. module as a string; it may be the name of a module within a package. The
  18. *path* parameter should be a sequence, and is used to augment the value
  19. of ``sys.path``, which is used to locate module source code.
  20. .. function:: readmodule_ex(module[, path=None])
  21. Like :func:`readmodule`, but the returned dictionary, in addition to
  22. mapping class names to class descriptor objects, also maps top-level
  23. function names to function descriptor objects. Moreover, if the module
  24. being read is a package, the key ``'__path__'`` in the returned
  25. dictionary has as its value a list which contains the package search
  26. path.
  27. .. _pyclbr-class-objects:
  28. Class Objects
  29. -------------
  30. The :class:`Class` objects used as values in the dictionary returned by
  31. :func:`readmodule` and :func:`readmodule_ex` provide the following data
  32. members:
  33. .. attribute:: Class.module
  34. The name of the module defining the class described by the class descriptor.
  35. .. attribute:: Class.name
  36. The name of the class.
  37. .. attribute:: Class.super
  38. A list of :class:`Class` objects which describe the immediate base
  39. classes of the class being described. Classes which are named as
  40. superclasses but which are not discoverable by :func:`readmodule` are
  41. listed as a string with the class name instead of as :class:`Class`
  42. objects.
  43. .. attribute:: Class.methods
  44. A dictionary mapping method names to line numbers.
  45. .. attribute:: Class.file
  46. Name of the file containing the ``class`` statement defining the class.
  47. .. attribute:: Class.lineno
  48. The line number of the ``class`` statement within the file named by
  49. :attr:`file`.
  50. .. _pyclbr-function-objects:
  51. Function Objects
  52. ----------------
  53. The :class:`Function` objects used as values in the dictionary returned by
  54. :func:`readmodule_ex` provide the following data members:
  55. .. attribute:: Function.module
  56. The name of the module defining the function described by the function
  57. descriptor.
  58. .. attribute:: Function.name
  59. The name of the function.
  60. .. attribute:: Function.file
  61. Name of the file containing the ``def`` statement defining the function.
  62. .. attribute:: Function.lineno
  63. The line number of the ``def`` statement within the file named by
  64. :attr:`file`.