~pythonregexp2.7/python/issue2636-11

« back to all changes in this revision

Viewing changes to Doc/reference/compound_stmts.rst

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-21 17:53:26 UTC
  • mfrom: (39025.1.14 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080921175326-92vaej2hc3yuecxb
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
422
422
when the function is called.
423
423
 
424
424
The function definition does not execute the function body; this gets executed
425
 
only when the function is called.
 
425
only when the function is called. [#]_
426
426
 
427
427
.. index::
428
428
  statement: @
509
509
   pair: name; binding
510
510
   pair: execution; frame
511
511
   single: inheritance
 
512
   single: docstring
512
513
 
513
514
A class definition defines a class object (see section :ref:`types`):
514
515
 
523
524
then executed in a new execution frame (see section :ref:`naming`), using a
524
525
newly created local namespace and the original global namespace. (Usually, the
525
526
suite contains only function definitions.)  When the class's suite finishes
526
 
execution, its execution frame is discarded but its local namespace is saved.  A
527
 
class object is then created using the inheritance list for the base classes and
528
 
the saved local namespace for the attribute dictionary.  The class name is bound
529
 
to this class object in the original local namespace.
 
527
execution, its execution frame is discarded but its local namespace is
 
528
saved. [#]_ A class object is then created using the inheritance list for the
 
529
base classes and the saved local namespace for the attribute dictionary.  The
 
530
class name is bound to this class object in the original local namespace.
530
531
 
531
532
**Programmer's note:** Variables defined in the class definition are class
532
533
variables; they are shared by all instances.  To create instance variables, they
538
539
class`\es, descriptors can be used to create instance variables with different
539
540
implementation details.
540
541
 
541
 
Class definitions, like function definitions, may be wrapped by one or
542
 
more :term:`decorator` expressions.  The evaluation rules for the
543
 
decorator expressions are the same as for functions.  The result must
544
 
be a class object, which is then bound to the class name.
 
542
Class definitions, like function definitions, may be wrapped by one or more
 
543
:term:`decorator` expressions.  The evaluation rules for the decorator
 
544
expressions are the same as for functions.  The result must be a class object,
 
545
which is then bound to the class name.
545
546
 
546
547
.. rubric:: Footnotes
547
548
 
551
552
.. [#] Currently, control "flows off the end" except in the case of an exception or the
552
553
   execution of a :keyword:`return`, :keyword:`continue`, or :keyword:`break`
553
554
   statement.
 
555
 
 
556
.. [#] A string literal appearing as the first statement in the function body is
 
557
   transformed into the function's ``__doc__`` attribute and therefore the
 
558
   function's :term:`docstring`.
 
559
 
 
560
.. [#] A string literal appearing as the first statement in the class body is
 
561
   transformed into the namespace's ``__doc__`` item and therefore the class's
 
562
   :term:`docstring`.