Skip to content
Snippets Groups Projects
topics.py 620 KiB
Newer Older
Georg Brandl's avatar
Georg Brandl committed
# -*- coding: utf-8 -*-
# Autogenerated by Sphinx on Mon Sep 12 10:47:11 2016
topics = {'assert': '\n'
           'The "assert" statement\n'
           '**********************\n'
           '\n'
           'Assert statements are a convenient way to insert debugging '
           'assertions\n'
           'into a program:\n'
           '\n'
           '   assert_stmt ::= "assert" expression ["," expression]\n'
           '\n'
           'The simple form, "assert expression", is equivalent to\n'
           '\n'
           '   if __debug__:\n'
           '       if not expression: raise AssertionError\n'
           '\n'
           'The extended form, "assert expression1, expression2", is '
           'equivalent to\n'
           '\n'
           '   if __debug__:\n'
           '       if not expression1: raise AssertionError(expression2)\n'
           '\n'
           'These equivalences assume that "__debug__" and "AssertionError" '
           'refer\n'
           'to the built-in variables with those names.  In the current\n'
           'implementation, the built-in variable "__debug__" is "True" under\n'
           'normal circumstances, "False" when optimization is requested '
           '(command\n'
           'line option -O).  The current code generator emits no code for an\n'
           'assert statement when optimization is requested at compile time.  '
           'Note\n'
           'that it is unnecessary to include the source code for the '
           'expression\n'
           'that failed in the error message; it will be displayed as part of '
           'the\n'
           'stack trace.\n'
           '\n'
           'Assignments to "__debug__" are illegal.  The value for the '
           'built-in\n'
           'variable is determined when the interpreter starts.\n',
 'assignment': '\n'
               'Assignment statements\n'
               '*********************\n'
               '\n'
               'Assignment statements are used to (re)bind names to values and '
               'to\n'
               'modify attributes or items of mutable objects:\n'
               '\n'
               '   assignment_stmt ::= (target_list "=")+ (starred_expression '
               '| yield_expression)\n'
               '   target_list     ::= target ("," target)* [","]\n'
               '   target          ::= identifier\n'
               '              | "(" [target_list] ")"\n'
               '              | "[" [target_list] "]"\n'
               '              | attributeref\n'
               '              | subscription\n'
               '              | slicing\n'
               '              | "*" target\n'
               '\n'
               '(See section Primaries for the syntax definitions for '
               '*attributeref*,\n'
               '*subscription*, and *slicing*.)\n'
               '\n'
               'An assignment statement evaluates the expression list '
               '(remember that\n'
               'this can be a single expression or a comma-separated list, the '
               'latter\n'
               'yielding a tuple) and assigns the single resulting object to '
               'each of\n'
               'the target lists, from left to right.\n'
               '\n'
               'Assignment is defined recursively depending on the form of the '
               'target\n'
               '(list). When a target is part of a mutable object (an '
               'attribute\n'
               'reference, subscription or slicing), the mutable object must\n'
               'ultimately perform the assignment and decide about its '
               'validity, and\n'
               'may raise an exception if the assignment is unacceptable.  The '
               'rules\n'
               'observed by various types and the exceptions raised are given '
               'with the\n'
               'definition of the object types (see section The standard type\n'
               'hierarchy).\n'
               '\n'
               'Assignment of an object to a target list, optionally enclosed '
               'in\n'
               'parentheses or square brackets, is recursively defined as '
               'follows.\n'
               '\n'
               '* If the target list is empty: The object must also be an '
               'empty\n'
               '  iterable.\n'
               '\n'
               '* If the target list is a single target in parentheses: The '
               'object\n'
               '  is assigned to that target.\n'
               '\n'
               '* If the target list is a comma-separated list of targets, or '
               'a\n'
               '  single target in square brackets: The object must be an '
               'iterable\n'
               '  with the same number of items as there are targets in the '
               'target\n'
               '  list, and the items are assigned, from left to right, to '
               'the\n'
               '  corresponding targets.\n'
               '  * If the target list contains one target prefixed with an\n'
               '    asterisk, called a "starred" target: The object must be '
               'an\n'
               '    iterable with at least as many items as there are targets '
               'in the\n'
               '    target list, minus one.  The first items of the iterable '
               'are\n'
               '    assigned, from left to right, to the targets before the '
               'starred\n'
               '    target.  The final items of the iterable are assigned to '
               'the\n'
               '    targets after the starred target.  A list of the remaining '
               'items\n'
               '    in the iterable is then assigned to the starred target '
               '(the list\n'
               '    can be empty).\n'
               '\n'
               '  * Else: The object must be an iterable with the same number '
               'of\n'
               '    items as there are targets in the target list, and the '
               'items are\n'
               '    assigned, from left to right, to the corresponding '
               'targets.\n'
               '\n'
               'Assignment of an object to a single target is recursively '
               'defined as\n'
               'follows.\n'
               '\n'
               '* If the target is an identifier (name):\n'
               '\n'
               '  * If the name does not occur in a "global" or "nonlocal" '
               'statement\n'
               '    in the current code block: the name is bound to the object '
               'in the\n'
               '    current local namespace.\n'
               '\n'
               '  * Otherwise: the name is bound to the object in the global\n'
               '    namespace or the outer namespace determined by '
               '"nonlocal",\n'
               '    respectively.\n'
               '\n'
               '  The name is rebound if it was already bound.  This may cause '
               'the\n'
               '  reference count for the object previously bound to the name '
               'to reach\n'
               '  zero, causing the object to be deallocated and its '
               'destructor (if it\n'
               '  has one) to be called.\n'
               '\n'
               '* If the target is an attribute reference: The primary '
               'expression in\n'
               '  the reference is evaluated.  It should yield an object with\n'
               '  assignable attributes; if this is not the case, "TypeError" '
               'is\n'
               '  raised.  That object is then asked to assign the assigned '
               'object to\n'
               '  the given attribute; if it cannot perform the assignment, it '
               'raises\n'
               '  an exception (usually but not necessarily '
               '"AttributeError").\n'
               '\n'
               '  Note: If the object is a class instance and the attribute '
               'reference\n'
               '  occurs on both sides of the assignment operator, the RHS '
               'expression,\n'
               '  "a.x" can access either an instance attribute or (if no '
               'instance\n'
               '  attribute exists) a class attribute.  The LHS target "a.x" '
               'is always\n'
               '  set as an instance attribute, creating it if necessary.  '
               'Thus, the\n'
               '  two occurrences of "a.x" do not necessarily refer to the '
               'same\n'
               '  attribute: if the RHS expression refers to a class '
               'attribute, the\n'
               '  LHS creates a new instance attribute as the target of the\n'
               '  assignment:\n'
               '\n'
               '     class Cls:\n'
               '         x = 3             # class variable\n'
               '     inst = Cls()\n'
               '     inst.x = inst.x + 1   # writes inst.x as 4 leaving Cls.x '
               'as 3\n'
               '\n'
               '  This description does not necessarily apply to descriptor\n'
               '  attributes, such as properties created with "property()".\n'
               '\n'
               '* If the target is a subscription: The primary expression in '
               'the\n'
               '  reference is evaluated.  It should yield either a mutable '
               'sequence\n'
               '  object (such as a list) or a mapping object (such as a '
               'dictionary).\n'
               '  Next, the subscript expression is evaluated.\n'
               '\n'
               '  If the primary is a mutable sequence object (such as a '
               'list), the\n'
               '  subscript must yield an integer.  If it is negative, the '
               "sequence's\n"
               '  length is added to it.  The resulting value must be a '
               'nonnegative\n'
               "  integer less than the sequence's length, and the sequence is "
               'asked\n'
               '  to assign the assigned object to its item with that index.  '
               'If the\n'
               '  index is out of range, "IndexError" is raised (assignment to '
               'a\n'
               '  subscripted sequence cannot add new items to a list).\n'
               '\n'
               '  If the primary is a mapping object (such as a dictionary), '
               'the\n'
               "  subscript must have a type compatible with the mapping's key "
               'type,\n'
               '  and the mapping is then asked to create a key/datum pair '
               'which maps\n'
               '  the subscript to the assigned object.  This can either '
               'replace an\n'
               '  existing key/value pair with the same key value, or insert a '
               'new\n'
               '  key/value pair (if no key with the same value existed).\n'
               '\n'
               '  For user-defined objects, the "__setitem__()" method is '
               'called with\n'
               '  appropriate arguments.\n'
               '\n'
               '* If the target is a slicing: The primary expression in the\n'
               '  reference is evaluated.  It should yield a mutable sequence '
               'object\n'
               '  (such as a list).  The assigned object should be a sequence '
               'object\n'
               '  of the same type.  Next, the lower and upper bound '
               'expressions are\n'
               '  evaluated, insofar they are present; defaults are zero and '
               'the\n'
               "  sequence's length.  The bounds should evaluate to integers. "
               'If\n'
               "  either bound is negative, the sequence's length is added to "
               'it.  The\n'
               '  resulting bounds are clipped to lie between zero and the '
               "sequence's\n"
               '  length, inclusive.  Finally, the sequence object is asked to '
               'replace\n'
               '  the slice with the items of the assigned sequence.  The '
               'length of\n'
               '  the slice may be different from the length of the assigned '
               'sequence,\n'
               '  thus changing the length of the target sequence, if the '
               'target\n'
               '  sequence allows it.\n'
               '\n'
               '**CPython implementation detail:** In the current '
               'implementation, the\n'
               'syntax for targets is taken to be the same as for expressions, '
               'and\n'
               'invalid syntax is rejected during the code generation phase, '
               'causing\n'
               'less detailed error messages.\n'
               '\n'
               'Although the definition of assignment implies that overlaps '
               'between\n'
               "the left-hand side and the right-hand side are 'simultaneous' "
               '(for\n'
               'example "a, b = b, a" swaps two variables), overlaps *within* '
               'the\n'
               'collection of assigned-to variables occur left-to-right, '
               'sometimes\n'
               'resulting in confusion.  For instance, the following program '
               'prints\n'
               '"[0, 2]":\n'
               '\n'
               '   x = [0, 1]\n'
               '   i = 0\n'
               '   i, x[i] = 1, 2         # i is updated, then x[i] is '
               'updated\n'
               '   print(x)\n'
               '\n'
               'See also:\n'
               '\n'
               '  **PEP 3132** - Extended Iterable Unpacking\n'
               '     The specification for the "*target" feature.\n'
               '\n'
               '\n'
               'Augmented assignment statements\n'
               '===============================\n'
               '\n'
               'Augmented assignment is the combination, in a single '
               'statement, of a\n'
               'binary operation and an assignment statement:\n'
               '\n'
               '   augmented_assignment_stmt ::= augtarget augop '
               '(expression_list | yield_expression)\n'
               '   augtarget                 ::= identifier | attributeref | '
               'subscription | slicing\n'
               '   augop                     ::= "+=" | "-=" | "*=" | "@=" | '
               '"/=" | "//=" | "%=" | "**="\n'
               '             | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
               '\n'
               '(See section Primaries for the syntax definitions of the last '
               'three\n'
               'symbols.)\n'
               '\n'
               'An augmented assignment evaluates the target (which, unlike '
               'normal\n'
               'assignment statements, cannot be an unpacking) and the '
               'expression\n'
               'list, performs the binary operation specific to the type of '
               'assignment\n'
               'on the two operands, and assigns the result to the original '
               'target.\n'
               'The target is only evaluated once.\n'
               '\n'
               'An augmented assignment expression like "x += 1" can be '
               'rewritten as\n'
               '"x = x + 1" to achieve a similar, but not exactly equal '
               'effect. In the\n'
               'augmented version, "x" is only evaluated once. Also, when '
               'possible,\n'
               'the actual operation is performed *in-place*, meaning that '
               'rather than\n'
               'creating a new object and assigning that to the target, the '
               'old object\n'
               'is modified instead.\n'
               '\n'
               'Unlike normal assignments, augmented assignments evaluate the '
               'left-\n'
               'hand side *before* evaluating the right-hand side.  For '
               'example, "a[i]\n'
               '+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and '
               'performs\n'
               'the addition, and lastly, it writes the result back to '
               '"a[i]".\n'
               '\n'
               'With the exception of assigning to tuples and multiple targets '
               'in a\n'
               'single statement, the assignment done by augmented assignment\n'
               'statements is handled the same way as normal assignments. '
               'Similarly,\n'
               'with the exception of the possible *in-place* behavior, the '
               'binary\n'
               'operation performed by augmented assignment is the same as the '
               'normal\n'
               'binary operations.\n'
               '\n'
               'For targets which are attribute references, the same caveat '
               'about\n'
               'class and instance attributes applies as for regular '
               'assignments.\n'
               '\n'
               '\n'
               'Annotated assignment statements\n'
               '===============================\n'
               '\n'
               'Annotation assignment is the combination, in a single '
               'statement, of a\n'
               'variable or attribute annotation and an optional assignment '
               'statement:\n'
               '\n'
               '   annotated_assignment_stmt ::= augtarget ":" expression ["=" '
               'expression]\n'
               '\n'
               'The difference from normal Assignment statements is that only '
               'single\n'
               'target and only single right hand side value is allowed.\n'
               '\n'
               'For simple names as assignment targets, if in class or module '
               'scope,\n'
               'the annotations are evaluated and stored in a special class or '
               'module\n'
               'attribute "__annotations__" that is a dictionary mapping from '
               'variable\n'
               'names (mangled if private) to evaluated annotations. This '
               'attribute is\n'
               'writable and is automatically created at the start of class or '
               'module\n'
               'body execution, if annotations are found statically.\n'
               '\n'
               'For expressions as assignment targets, the annotations are '
               'evaluated\n'
               'if in class or module scope, but not stored.\n'
               '\n'
               'If a name is annotated in a function scope, then this name is '
               'local\n'
               'for that scope. Annotations are never evaluated and stored in '
               'function\n'
               'scopes.\n'
               '\n'
               'If the right hand side is present, an annotated assignment '
               'performs\n'
               'the actual assignment before evaluating annotations (where\n'
               'applicable). If the right hand side is not present for an '
               'expression\n'
               'target, then the interpreter evaluates the target except for '
               'the last\n'
               '"__setitem__()" or "__setattr__()" call.\n'
               '\n'
               'See also: **PEP 526** - Variable and attribute annotation '
               'syntax\n'
               '  **PEP 484** - Type hints\n',
 'atom-identifiers': '\n'
                     'Identifiers (Names)\n'
                     '*******************\n'
                     '\n'
                     'An identifier occurring as an atom is a name.  See '
                     'section Identifiers\n'
                     'and keywords for lexical definition and section Naming '
                     'and binding for\n'
                     'documentation of naming and binding.\n'
                     '\n'
                     'When the name is bound to an object, evaluation of the '
                     'atom yields\n'
                     'that object. When a name is not bound, an attempt to '
                     'evaluate it\n'
                     'raises a "NameError" exception.\n'
                     '\n'
                     '**Private name mangling:** When an identifier that '
                     'textually occurs in\n'
                     'a class definition begins with two or more underscore '
                     'characters and\n'
                     'does not end in two or more underscores, it is '
                     'considered a *private\n'
                     'name* of that class. Private names are transformed to a '
                     'longer form\n'
                     'before code is generated for them.  The transformation '
                     'inserts the\n'
                     'class name, with leading underscores removed and a '
                     'single underscore\n'
                     'inserted, in front of the name.  For example, the '
                     'identifier "__spam"\n'
                     'occurring in a class named "Ham" will be transformed to '
                     '"_Ham__spam".\n'
                     'This transformation is independent of the syntactical '
                     'context in which\n'
                     'the identifier is used.  If the transformed name is '
                     'extremely long\n'
                     '(longer than 255 characters), implementation defined '
                     'truncation may\n'
                     'happen. If the class name consists only of underscores, '
                     'no\n'
                     'transformation is done.\n',
 'atom-literals': '\n'
                  'Literals\n'
                  '********\n'
                  '\n'
                  'Python supports string and bytes literals and various '
                  'numeric\n'
                  'literals:\n'
                  '\n'
                  '   literal ::= stringliteral | bytesliteral\n'
                  '               | integer | floatnumber | imagnumber\n'
                  '\n'
                  'Evaluation of a literal yields an object of the given type '
                  '(string,\n'
                  'bytes, integer, floating point number, complex number) with '
                  'the given\n'
                  'value.  The value may be approximated in the case of '
                  'floating point\n'
                  'and imaginary (complex) literals.  See section Literals for '
                  'details.\n'
                  '\n'
                  'All literals correspond to immutable data types, and hence '
                  'the\n'
                  "object's identity is less important than its value.  "
                  'Multiple\n'
                  'evaluations of literals with the same value (either the '
                  'same\n'
                  'occurrence in the program text or a different occurrence) '
                  'may obtain\n'
                  'the same object or a different object with the same '
                  'value.\n',
 'attribute-access': '\n'
                     'Customizing attribute access\n'
                     '****************************\n'
                     '\n'
                     'The following methods can be defined to customize the '
                     'meaning of\n'
                     'attribute access (use of, assignment to, or deletion of '
                     '"x.name") for\n'
                     'class instances.\n'
                     '\n'
                     'object.__getattr__(self, name)\n'
                     '\n'
                     '   Called when an attribute lookup has not found the '
                     'attribute in the\n'
                     '   usual places (i.e. it is not an instance attribute '
                     'nor is it found\n'
                     '   in the class tree for "self").  "name" is the '
                     'attribute name. This\n'
                     '   method should return the (computed) attribute value '
                     'or raise an\n'
                     '   "AttributeError" exception.\n'
                     '\n'
                     '   Note that if the attribute is found through the '
                     'normal mechanism,\n'
                     '   "__getattr__()" is not called.  (This is an '
                     'intentional asymmetry\n'
                     '   between "__getattr__()" and "__setattr__()".) This is '
                     'done both for\n'
                     '   efficiency reasons and because otherwise '
                     '"__getattr__()" would have\n'
                     '   no way to access other attributes of the instance.  '
                     'Note that at\n'
                     '   least for instance variables, you can fake total '
                     'control by not\n'
                     '   inserting any values in the instance attribute '
                     'dictionary (but\n'
                     '   instead inserting them in another object).  See the\n'
                     '   "__getattribute__()" method below for a way to '
                     'actually get total\n'
                     '   control over attribute access.\n'
                     '\n'
                     'object.__getattribute__(self, name)\n'
                     '\n'
                     '   Called unconditionally to implement attribute '
                     'accesses for\n'
                     '   instances of the class. If the class also defines '
                     '"__getattr__()",\n'
                     '   the latter will not be called unless '
                     '"__getattribute__()" either\n'
                     '   calls it explicitly or raises an "AttributeError". '
                     'This method\n'
                     '   should return the (computed) attribute value or raise '
                     'an\n'
                     '   "AttributeError" exception. In order to avoid '
                     'infinite recursion in\n'
                     '   this method, its implementation should always call '
                     'the base class\n'
                     '   method with the same name to access any attributes it '
                     'needs, for\n'
                     '   example, "object.__getattribute__(self, name)".\n'
                     '\n'
                     '   Note: This method may still be bypassed when looking '
                     'up special\n'
                     '     methods as the result of implicit invocation via '
                     'language syntax\n'
                     '     or built-in functions. See Special method lookup.\n'
                     '\n'
                     'object.__setattr__(self, name, value)\n'
                     '\n'
                     '   Called when an attribute assignment is attempted.  '
                     'This is called\n'
                     '   instead of the normal mechanism (i.e. store the value '
                     'in the\n'
                     '   instance dictionary). *name* is the attribute name, '
                     '*value* is the\n'
                     '   value to be assigned to it.\n'
                     '\n'
                     '   If "__setattr__()" wants to assign to an instance '
                     'attribute, it\n'
                     '   should call the base class method with the same name, '
                     'for example,\n'
                     '   "object.__setattr__(self, name, value)".\n'
                     '\n'
                     'object.__delattr__(self, name)\n'
                     '\n'
                     '   Like "__setattr__()" but for attribute deletion '
                     'instead of\n'
                     '   assignment.  This should only be implemented if "del '
                     'obj.name" is\n'
                     '   meaningful for the object.\n'
                     '\n'
                     'object.__dir__(self)\n'
                     '\n'
                     '   Called when "dir()" is called on the object. A '
                     'sequence must be\n'
                     '   returned. "dir()" converts the returned sequence to a '
                     'list and\n'
                     '   sorts it.\n'
                     '\n'
                     '\n'
                     'Implementing Descriptors\n'
                     '========================\n'
                     '\n'
                     'The following methods only apply when an instance of the '
                     'class\n'
                     'containing the method (a so-called *descriptor* class) '
                     'appears in an\n'
                     '*owner* class (the descriptor must be in either the '
                     "owner's class\n"
                     'dictionary or in the class dictionary for one of its '
                     'parents).  In the\n'
                     'examples below, "the attribute" refers to the attribute '
                     'whose name is\n'
                     "the key of the property in the owner class' "
                     '"__dict__".\n'
                     '\n'
                     'object.__get__(self, instance, owner)\n'
                     '\n'
                     '   Called to get the attribute of the owner class (class '
                     'attribute\n'
                     '   access) or of an instance of that class (instance '
                     'attribute\n'
                     '   access). *owner* is always the owner class, while '
                     '*instance* is the\n'
                     '   instance that the attribute was accessed through, or '
                     '"None" when\n'
                     '   the attribute is accessed through the *owner*.  This '
                     'method should\n'
                     '   return the (computed) attribute value or raise an '
                     '"AttributeError"\n'
                     '   exception.\n'
                     '\n'
                     'object.__set__(self, instance, value)\n'
                     '\n'
                     '   Called to set the attribute on an instance *instance* '
                     'of the owner\n'
                     '   class to a new value, *value*.\n'
                     '\n'
                     'object.__delete__(self, instance)\n'
                     '\n'
                     '   Called to delete the attribute on an instance '
                     '*instance* of the\n'
                     '   owner class.\n'
                     '\n'
                     'object.__set_name__(self, owner, name)\n'
                     '\n'
                     '   Called at the time the owning class *owner* is '
                     'created. The\n'
                     '   descriptor has been assigned to *name*.\n'
                     '\n'
                     '   New in version 3.6.\n'
                     '\n'
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
                     'The attribute "__objclass__" is interpreted by the '
                     '"inspect" module as\n'
                     'specifying the class where this object was defined '
                     '(setting this\n'
                     'appropriately can assist in runtime introspection of '
                     'dynamic class\n'
                     'attributes). For callables, it may indicate that an '
                     'instance of the\n'
                     'given type (or a subclass) is expected or required as '
                     'the first\n'
                     'positional argument (for example, CPython sets this '
                     'attribute for\n'
                     'unbound methods that are implemented in C).\n'
                     '\n'
                     '\n'
                     'Invoking Descriptors\n'
                     '====================\n'
                     '\n'
                     'In general, a descriptor is an object attribute with '
                     '"binding\n'
                     'behavior", one whose attribute access has been '
                     'overridden by methods\n'
                     'in the descriptor protocol:  "__get__()", "__set__()", '
                     'and\n'
                     '"__delete__()". If any of those methods are defined for '
                     'an object, it\n'
                     'is said to be a descriptor.\n'
                     '\n'
                     'The default behavior for attribute access is to get, '
                     'set, or delete\n'
                     "the attribute from an object's dictionary. For instance, "
                     '"a.x" has a\n'
                     'lookup chain starting with "a.__dict__[\'x\']", then\n'
                     '"type(a).__dict__[\'x\']", and continuing through the '
                     'base classes of\n'
                     '"type(a)" excluding metaclasses.\n'
                     '\n'
                     'However, if the looked-up value is an object defining '
                     'one of the\n'
                     'descriptor methods, then Python may override the default '
                     'behavior and\n'
                     'invoke the descriptor method instead.  Where this occurs '
                     'in the\n'
                     'precedence chain depends on which descriptor methods '
                     'were defined and\n'
                     'how they were called.\n'
                     '\n'
                     'The starting point for descriptor invocation is a '
                     'binding, "a.x". How\n'
                     'the arguments are assembled depends on "a":\n'
                     '\n'
                     'Direct Call\n'
                     '   The simplest and least common call is when user code '
                     'directly\n'
                     '   invokes a descriptor method:    "x.__get__(a)".\n'
                     '\n'
                     'Instance Binding\n'
                     '   If binding to an object instance, "a.x" is '
                     'transformed into the\n'
                     '   call: "type(a).__dict__[\'x\'].__get__(a, type(a))".\n'
                     '\n'
                     'Class Binding\n'
                     '   If binding to a class, "A.x" is transformed into the '
                     'call:\n'
                     '   "A.__dict__[\'x\'].__get__(None, A)".\n'
                     '\n'
                     'Super Binding\n'
                     '   If "a" is an instance of "super", then the binding '
                     '"super(B,\n'
                     '   obj).m()" searches "obj.__class__.__mro__" for the '
                     'base class "A"\n'
                     '   immediately preceding "B" and then invokes the '
                     'descriptor with the\n'
                     '   call: "A.__dict__[\'m\'].__get__(obj, '
                     'obj.__class__)".\n'
                     '\n'
                     'For instance bindings, the precedence of descriptor '
                     'invocation depends\n'
                     'on the which descriptor methods are defined.  A '
                     'descriptor can define\n'
                     'any combination of "__get__()", "__set__()" and '
                     '"__delete__()".  If it\n'
                     'does not define "__get__()", then accessing the '
                     'attribute will return\n'
                     'the descriptor object itself unless there is a value in '
                     "the object's\n"
                     'instance dictionary.  If the descriptor defines '
                     '"__set__()" and/or\n'
                     '"__delete__()", it is a data descriptor; if it defines '
                     'neither, it is\n'
                     'a non-data descriptor.  Normally, data descriptors '
                     'define both\n'
                     '"__get__()" and "__set__()", while non-data descriptors '
                     'have just the\n'
                     '"__get__()" method.  Data descriptors with "__set__()" '
                     'and "__get__()"\n'
                     'defined always override a redefinition in an instance '
                     'dictionary.  In\n'
                     'contrast, non-data descriptors can be overridden by '
                     'instances.\n'
                     '\n'
                     'Python methods (including "staticmethod()" and '
                     '"classmethod()") are\n'
                     'implemented as non-data descriptors.  Accordingly, '
                     'instances can\n'
                     'redefine and override methods.  This allows individual '
                     'instances to\n'
                     'acquire behaviors that differ from other instances of '
                     'the same class.\n'
                     '\n'
                     'The "property()" function is implemented as a data '
                     'descriptor.\n'
                     'Accordingly, instances cannot override the behavior of a '
                     'property.\n'
                     '\n'
                     '\n'
                     '__slots__\n'
                     '=========\n'
                     '\n'
                     'By default, instances of classes have a dictionary for '
                     'attribute\n'
                     'storage.  This wastes space for objects having very few '
                     'instance\n'
                     'variables.  The space consumption can become acute when '
                     'creating large\n'
                     'numbers of instances.\n'
                     '\n'
                     'The default can be overridden by defining *__slots__* in '
                     'a class\n'
                     'definition. The *__slots__* declaration takes a sequence '
                     'of instance\n'
                     'variables and reserves just enough space in each '
                     'instance to hold a\n'
                     'value for each variable.  Space is saved because '
                     '*__dict__* is not\n'
                     'created for each instance.\n'
                     '\n'
                     'object.__slots__\n'
                     '\n'
                     '   This class variable can be assigned a string, '
                     'iterable, or sequence\n'
                     '   of strings with variable names used by instances.  '
                     '*__slots__*\n'
                     '   reserves space for the declared variables and '
                     'prevents the\n'
                     '   automatic creation of *__dict__* and *__weakref__* '
                     'for each\n'
                     '   instance.\n'
                     '\n'
                     '\n'
                     'Notes on using *__slots__*\n'
                     '--------------------------\n'
                     '\n'
                     '* When inheriting from a class without *__slots__*, the '
                     '*__dict__*\n'
                     '  attribute of that class will always be accessible, so '
                     'a *__slots__*\n'
                     '  definition in the subclass is meaningless.\n'
                     '\n'
                     '* Without a *__dict__* variable, instances cannot be '
                     'assigned new\n'
                     '  variables not listed in the *__slots__* definition.  '
                     'Attempts to\n'
                     '  assign to an unlisted variable name raises '
                     '"AttributeError". If\n'
                     '  dynamic assignment of new variables is desired, then '
                     'add\n'
                     '  "\'__dict__\'" to the sequence of strings in the '
                     '*__slots__*\n'
                     '  declaration.\n'
                     '\n'
                     '* Without a *__weakref__* variable for each instance, '
                     'classes\n'
                     '  defining *__slots__* do not support weak references to '
                     'its\n'
                     '  instances. If weak reference support is needed, then '
                     'add\n'
                     '  "\'__weakref__\'" to the sequence of strings in the '
                     '*__slots__*\n'
                     '  declaration.\n'
                     '\n'
                     '* *__slots__* are implemented at the class level by '
                     'creating\n'
                     '  descriptors (Implementing Descriptors) for each '
                     'variable name.  As a\n'
                     '  result, class attributes cannot be used to set default '
                     'values for\n'
                     '  instance variables defined by *__slots__*; otherwise, '
                     'the class\n'
                     '  attribute would overwrite the descriptor assignment.\n'
                     '\n'
                     '* The action of a *__slots__* declaration is limited to '
                     'the class\n'
                     '  where it is defined.  As a result, subclasses will '
                     'have a *__dict__*\n'
                     '  unless they also define *__slots__* (which must only '
                     'contain names\n'
                     '  of any *additional* slots).\n'
                     '\n'
                     '* If a class defines a slot also defined in a base '
                     'class, the\n'
                     '  instance variable defined by the base class slot is '
                     'inaccessible\n'
                     '  (except by retrieving its descriptor directly from the '
                     'base class).\n'
                     '  This renders the meaning of the program undefined.  In '
                     'the future, a\n'
                     '  check may be added to prevent this.\n'
                     '\n'
                     '* Nonempty *__slots__* does not work for classes derived '
                     'from\n'
                     '  "variable-length" built-in types such as "int", '
                     '"bytes" and "tuple".\n'
                     '\n'
                     '* Any non-string iterable may be assigned to '
                     '*__slots__*. Mappings\n'
                     '  may also be used; however, in the future, special '
                     'meaning may be\n'
                     '  assigned to the values corresponding to each key.\n'
                     '\n'
                     '* *__class__* assignment works only if both classes have '
                     'the same\n'
                     '  *__slots__*.\n',
 'attribute-references': '\n'
                         'Attribute references\n'
                         '********************\n'
                         '\n'
                         'An attribute reference is a primary followed by a '
                         'period and a name:\n'
                         '\n'
                         '   attributeref ::= primary "." identifier\n'
                         '\n'
                         'The primary must evaluate to an object of a type '
                         'that supports\n'
                         'attribute references, which most objects do.  This '
                         'object is then\n'
                         'asked to produce the attribute whose name is the '
                         'identifier.  This\n'
                         'production can be customized by overriding the '
                         '"__getattr__()" method.\n'
                         'If this attribute is not available, the exception '
                         '"AttributeError" is\n'
                         'raised.  Otherwise, the type and value of the object '
                         'produced is\n'
                         'determined by the object.  Multiple evaluations of '
                         'the same attribute\n'
                         'reference may yield different objects.\n',
 'augassign': '\n'
              'Augmented assignment statements\n'
              '*******************************\n'
              '\n'
              'Augmented assignment is the combination, in a single statement, '
              'of a\n'
              'binary operation and an assignment statement:\n'
              '\n'
              '   augmented_assignment_stmt ::= augtarget augop '
              '(expression_list | yield_expression)\n'
              '   augtarget                 ::= identifier | attributeref | '
              'subscription | slicing\n'
              '   augop                     ::= "+=" | "-=" | "*=" | "@=" | '
              '"/=" | "//=" | "%=" | "**="\n'
              '             | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
              '\n'
              '(See section Primaries for the syntax definitions of the last '
              'three\n'
              'symbols.)\n'
              '\n'
              'An augmented assignment evaluates the target (which, unlike '
              'normal\n'
              'assignment statements, cannot be an unpacking) and the '
              'expression\n'
              'list, performs the binary operation specific to the type of '
              'assignment\n'
              'on the two operands, and assigns the result to the original '
              'target.\n'
              'The target is only evaluated once.\n'
              '\n'
              'An augmented assignment expression like "x += 1" can be '
              'rewritten as\n'
              '"x = x + 1" to achieve a similar, but not exactly equal effect. '
              'In the\n'
              'augmented version, "x" is only evaluated once. Also, when '
              'possible,\n'
              'the actual operation is performed *in-place*, meaning that '
              'rather than\n'
              'creating a new object and assigning that to the target, the old '
              'object\n'
              'is modified instead.\n'
              '\n'
              'Unlike normal assignments, augmented assignments evaluate the '
              'left-\n'
              'hand side *before* evaluating the right-hand side.  For '
              'example, "a[i]\n'
              '+= f(x)" first looks-up "a[i]", then it evaluates "f(x)" and '
              'performs\n'
              'the addition, and lastly, it writes the result back to "a[i]".\n'
              '\n'
              'With the exception of assigning to tuples and multiple targets '
              'in a\n'
              'single statement, the assignment done by augmented assignment\n'
              'statements is handled the same way as normal assignments. '
              'Similarly,\n'
              'with the exception of the possible *in-place* behavior, the '
              'binary\n'
              'operation performed by augmented assignment is the same as the '
              'normal\n'
              'binary operations.\n'
              '\n'
              'For targets which are attribute references, the same caveat '
              'about\n'
              'class and instance attributes applies as for regular '
              'assignments.\n',
 'binary': '\n'
           'Binary arithmetic operations\n'
           '****************************\n'
           '\n'
           'The binary arithmetic operations have the conventional priority\n'
           'levels.  Note that some of these operations also apply to certain '
           'non-\n'
           'numeric types.  Apart from the power operator, there are only two\n'
           'levels, one for multiplicative operators and one for additive\n'
           'operators:\n'
           '\n'
           '   m_expr ::= u_expr | m_expr "*" u_expr | m_expr "@" m_expr |\n'
           '              m_expr "//" u_expr| m_expr "/" u_expr |\n'
           '              m_expr "%" u_expr\n'
           '   a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n'
           '\n'
           'The "*" (multiplication) operator yields the product of its '
           'arguments.\n'
           'The arguments must either both be numbers, or one argument must be '
           'an\n'
           'integer and the other must be a sequence. In the former case, the\n'
           'numbers are converted to a common type and then multiplied '
           'together.\n'
           'In the latter case, sequence repetition is performed; a negative\n'
           'repetition factor yields an empty sequence.\n'
           '\n'
           'The "@" (at) operator is intended to be used for matrix\n'
           'multiplication.  No builtin Python types implement this operator.\n'
           '\n'
           'New in version 3.5.\n'
           '\n'
           'The "/" (division) and "//" (floor division) operators yield the\n'
           'quotient of their arguments.  The numeric arguments are first\n'
           'converted to a common type. Division of integers yields a float, '
           'while\n'
           'floor division of integers results in an integer; the result is '
           'that\n'
           "of mathematical division with the 'floor' function applied to the\n"
           'result.  Division by zero raises the "ZeroDivisionError" '
           'exception.\n'
           '\n'
           'The "%" (modulo) operator yields the remainder from the division '
           'of\n'
           'the first argument by the second.  The numeric arguments are '
           'first\n'
           'converted to a common type.  A zero right argument raises the\n'
           '"ZeroDivisionError" exception.  The arguments may be floating '
           'point\n'
           'numbers, e.g., "3.14%0.7" equals "0.34" (since "3.14" equals '
           '"4*0.7 +\n'
           '0.34".)  The modulo operator always yields a result with the same '
           'sign\n'
           'as its second operand (or zero); the absolute value of the result '
           'is\n'
           'strictly smaller than the absolute value of the second operand '
           '[1].\n'
           '\n'
           'The floor division and modulo operators are connected by the '
           'following\n'
           'identity: "x == (x//y)*y + (x%y)".  Floor division and modulo are '
           'also\n'
           'connected with the built-in function "divmod()": "divmod(x, y) ==\n'
           '(x//y, x%y)". [2].\n'
           '\n'
           'In addition to performing the modulo operation on numbers, the '
           '"%"\n'
           'operator is also overloaded by string objects to perform '
           'old-style\n'
           'string formatting (also known as interpolation).  The syntax for\n'
           'string formatting is described in the Python Library Reference,\n'
           'section printf-style String Formatting.\n'
           '\n'
           'The floor division operator, the modulo operator, and the '
           '"divmod()"\n'
           'function are not defined for complex numbers.  Instead, convert to '
           'a\n'
           'floating point number using the "abs()" function if appropriate.\n'
           '\n'
           'The "+" (addition) operator yields the sum of its arguments.  The\n'
           'arguments must either both be numbers or both be sequences of the '
           'same\n'
           'type.  In the former case, the numbers are converted to a common '
           'type\n'
           'and then added together. In the latter case, the sequences are\n'
           'concatenated.\n'
           '\n'
           'The "-" (subtraction) operator yields the difference of its '
           'arguments.\n'
           'The numeric arguments are first converted to a common type.\n',
 'bitwise': '\n'
            'Binary bitwise operations\n'
            '*************************\n'
            '\n'
            'Each of the three bitwise operations has a different priority '
            'level:\n'
            '\n'
            '   and_expr ::= shift_expr | and_expr "&" shift_expr\n'
            '   xor_expr ::= and_expr | xor_expr "^" and_expr\n'
            '   or_expr  ::= xor_expr | or_expr "|" xor_expr\n'
            '\n'
            'The "&" operator yields the bitwise AND of its arguments, which '
            'must\n'
            'be integers.\n'
            '\n'
            'The "^" operator yields the bitwise XOR (exclusive OR) of its\n'
            'arguments, which must be integers.\n'
            '\n'
            'The "|" operator yields the bitwise (inclusive) OR of its '
            'arguments,\n'
            'which must be integers.\n',
 'bltin-code-objects': '\n'
                       'Code Objects\n'
                       '************\n'
                       '\n'
                       'Code objects are used by the implementation to '
                       'represent "pseudo-\n'
                       'compiled" executable Python code such as a function '
                       'body. They differ\n'
                       "from function objects because they don't contain a "
                       'reference to their\n'
                       'global execution environment.  Code objects are '
                       'returned by the built-\n'
                       'in "compile()" function and can be extracted from '
                       'function objects\n'
                       'through their "__code__" attribute. See also the '
                       '"code" module.\n'
                       '\n'
                       'A code object can be executed or evaluated by passing '
                       'it (instead of a\n'
                       'source string) to the "exec()" or "eval()"  built-in '
                       'functions.\n'
                       '\n'
                       'See The standard type hierarchy for more '
                       'information.\n',
 'bltin-ellipsis-object': '\n'
                          'The Ellipsis Object\n'
                          '*******************\n'
                          '\n'
                          'This object is commonly used by slicing (see '
                          'Slicings).  It supports\n'
                          'no special operations.  There is exactly one '
                          'ellipsis object, named\n'
                          '"Ellipsis" (a built-in name).  "type(Ellipsis)()" '
                          'produces the\n'
                          '"Ellipsis" singleton.\n'
                          '\n'
                          'It is written as "Ellipsis" or "...".\n',
 'bltin-null-object': '\n'
                      'The Null Object\n'
                      '***************\n'
                      '\n'
                      "This object is returned by functions that don't "
                      'explicitly return a\n'
                      'value.  It supports no special operations.  There is '
                      'exactly one null\n'
                      'object, named "None" (a built-in name).  "type(None)()" '
                      'produces the\n'
                      'same singleton.\n'
                      '\n'
                      'It is written as "None".\n',
 'bltin-type-objects': '\n'
                       'Type Objects\n'
                       '************\n'
                       '\n'
                       'Type objects represent the various object types.  An '
                       "object's type is\n"
                       'accessed by the built-in function "type()".  There are '
                       'no special\n'
                       'operations on types.  The standard module "types" '
                       'defines names for\n'
                       'all standard built-in types.\n'
                       '\n'
                       'Types are written like this: "<class \'int\'>".\n',
 'booleans': '\n'
             'Boolean operations\n'
             '******************\n'
             '\n'
             '   or_test  ::= and_test | or_test "or" and_test\n'
             '   and_test ::= not_test | and_test "and" not_test\n'
             '   not_test ::= comparison | "not" not_test\n'
             '\n'
             'In the context of Boolean operations, and also when expressions '
             'are\n'
             'used by control flow statements, the following values are '
             'interpreted\n'
             'as false: "False", "None", numeric zero of all types, and empty\n'
             'strings and containers (including strings, tuples, lists,\n'
             'dictionaries, sets and frozensets).  All other values are '
             'interpreted\n'
             'as true.  User-defined objects can customize their truth value '
             'by\n'
             'providing a "__bool__()" method.\n'
             '\n'
             'The operator "not" yields "True" if its argument is false, '
             '"False"\n'
             'otherwise.\n'
             '\n'
             'The expression "x and y" first evaluates *x*; if *x* is false, '
             'its\n'
             'value is returned; otherwise, *y* is evaluated and the resulting '
             'value\n'
             'is returned.\n'
             '\n'
             'The expression "x or y" first evaluates *x*; if *x* is true, its '
             'value\n'
             'is returned; otherwise, *y* is evaluated and the resulting value '
             'is\n'
             'returned.\n'
             '\n'
             '(Note that neither "and" nor "or" restrict the value and type '
             'they\n'
             'return to "False" and "True", but rather return the last '
             'evaluated\n'
             'argument.  This is sometimes useful, e.g., if "s" is a string '
             'that\n'
             'should be replaced by a default value if it is empty, the '
             'expression\n'
             '"s or \'foo\'" yields the desired value.  Because "not" has to '
             'create a\n'
             'new value, it returns a boolean value regardless of the type of '
             'its\n'
             'argument (for example, "not \'foo\'" produces "False" rather '
             'than "\'\'".)\n',
 'break': '\n'
          'The "break" statement\n'
          '*********************\n'
          '\n'
          '   break_stmt ::= "break"\n'
          '\n'
          '"break" may only occur syntactically nested in a "for" or "while"\n'
          'loop, but not nested in a function or class definition within that\n'
          'loop.\n'
          '\n'
          'It terminates the nearest enclosing loop, skipping the optional '
          '"else"\n'
          'clause if the loop has one.\n'
          '\n'
          'If a "for" loop is terminated by "break", the loop control target\n'
          'keeps its current value.\n'
          '\n'
          'When "break" passes control out of a "try" statement with a '
          '"finally"\n'
          'clause, that "finally" clause is executed before really leaving '
          'the\n'
          'loop.\n',
 'callable-types': '\n'
                   'Emulating callable objects\n'
                   '**************************\n'
                   '\n'
                   'object.__call__(self[, args...])\n'
                   '\n'
                   '   Called when the instance is "called" as a function; if '
                   'this method\n'
                   '   is defined, "x(arg1, arg2, ...)" is a shorthand for\n'
                   '   "x.__call__(arg1, arg2, ...)".\n',
 'calls': '\n'
          'Calls\n'
          '*****\n'
          '\n'
          'A call calls a callable object (e.g., a *function*) with a '
          'possibly\n'
          'empty series of *arguments*:\n'
          '\n'
          '   call                 ::= primary "(" [argument_list [","] | '
          'comprehension] ")"\n'
          '   argument_list        ::= positional_arguments ["," '
          'starred_and_keywords]\n'
          '                       ["," keywords_arguments]\n'
          '                     | starred_and_keywords ["," '
          'keywords_arguments]\n'
          '                     | keywords_arguments\n'
          '   positional_arguments ::= ["*"] expression ("," ["*"] '
          'expression)*\n'
          '   starred_and_keywords ::= ("*" expression | keyword_item)\n'
          '                            ("," "*" expression | "," '
          'keyword_item)*\n'
          '   keywords_arguments   ::= (keyword_item | "**" expression)\n'
          '                          ("," keyword_item | "**" expression)*\n'
          '   keyword_item         ::= identifier "=" expression\n'
          '\n'
          'An optional trailing comma may be present after the positional and\n'
          'keyword arguments but does not affect the semantics.\n'
          '\n'
          'The primary must evaluate to a callable object (user-defined\n'
          'functions, built-in functions, methods of built-in objects, class\n'
          'objects, methods of class instances, and all objects having a\n'
          '"__call__()" method are callable).  All argument expressions are\n'
          'evaluated before the call is attempted.  Please refer to section\n'
          'Function definitions for the syntax of formal *parameter* lists.\n'
          '\n'
          'If keyword arguments are present, they are first converted to\n'
          'positional arguments, as follows.  First, a list of unfilled slots '
          'is\n'
          'created for the formal parameters.  If there are N positional\n'
          'arguments, they are placed in the first N slots.  Next, for each\n'
          'keyword argument, the identifier is used to determine the\n'
          'corresponding slot (if the identifier is the same as the first '
          'formal\n'
          'parameter name, the first slot is used, and so on).  If the slot '
          'is\n'
          'already filled, a "TypeError" exception is raised. Otherwise, the\n'
          'value of the argument is placed in the slot, filling it (even if '
          'the\n'
          'expression is "None", it fills the slot).  When all arguments have\n'
          'been processed, the slots that are still unfilled are filled with '
          'the\n'
          'corresponding default value from the function definition.  '
          '(Default\n'
          'values are calculated, once, when the function is defined; thus, a\n'
          'mutable object such as a list or dictionary used as default value '
          'will\n'
          "be shared by all calls that don't specify an argument value for "
          'the\n'
          'corresponding slot; this should usually be avoided.)  If there are '
          'any\n'
          'unfilled slots for which no default value is specified, a '
          '"TypeError"\n'
          'exception is raised.  Otherwise, the list of filled slots is used '
          'as\n'
          'the argument list for the call.\n'
          '\n'
          '**CPython implementation detail:** An implementation may provide\n'
          'built-in functions whose positional parameters do not have names, '
          'even\n'
          "if they are 'named' for the purpose of documentation, and which\n"
          'therefore cannot be supplied by keyword.  In CPython, this is the '
          'case\n'
          'for functions implemented in C that use "PyArg_ParseTuple()" to '
          'parse\n'
          'their arguments.\n'
          '\n'
          'If there are more positional arguments than there are formal '
          'parameter\n'
          'slots, a "TypeError" exception is raised, unless a formal '
          'parameter\n'
          'using the syntax "*identifier" is present; in this case, that '
          'formal\n'
          'parameter receives a tuple containing the excess positional '
          'arguments\n'
          '(or an empty tuple if there were no excess positional arguments).\n'
          '\n'
          'If any keyword argument does not correspond to a formal parameter\n'
          'name, a "TypeError" exception is raised, unless a formal parameter\n'
          'using the syntax "**identifier" is present; in this case, that '
          'formal\n'
          'parameter receives a dictionary containing the excess keyword\n'
          'arguments (using the keywords as keys and the argument values as\n'
          'corresponding values), or a (new) empty dictionary if there were '
          'no\n'
          'excess keyword arguments.\n'
          '\n'
          'If the syntax "*expression" appears in the function call, '
          '"expression"\n'
          'must evaluate to an *iterable*.  Elements from these iterables are\n'
          'treated as if they were additional positional arguments.  For the '
          'call\n'
          '"f(x1, x2, *y, x3, x4)", if *y* evaluates to a sequence *y1*, ...,\n'
          '*yM*, this is equivalent to a call with M+4 positional arguments '
          '*x1*,\n'
          '*x2*, *y1*, ..., *yM*, *x3*, *x4*.\n'
          '\n'
          'A consequence of this is that although the "*expression" syntax '
          'may\n'
          'appear *after* explicit keyword arguments, it is processed '
          '*before*\n'
          'the keyword arguments (and any "**expression" arguments -- see '
          'below).\n'
          'So:\n'
          '\n'
          '   >>> def f(a, b):\n'
          '   ...     print(a, b)\n'
          '   ...\n'
          '   >>> f(b=1, *(2,))\n'
          '   2 1\n'
          '   >>> f(a=1, *(2,))\n'
          '   Traceback (most recent call last):\n'
          '     File "<stdin>", line 1, in ?\n'
          "   TypeError: f() got multiple values for keyword argument 'a'\n"
          '   >>> f(1, *(2,))\n'
          '   1 2\n'
          '\n'
          'It is unusual for both keyword arguments and the "*expression" '
          'syntax\n'
          'to be used in the same call, so in practice this confusion does '
          'not\n'
          'arise.\n'
          '\n'
          'If the syntax "**expression" appears in the function call,\n'
          '"expression" must evaluate to a *mapping*, the contents of which '
          'are\n'
          'treated as additional keyword arguments.  If a keyword is already\n'
          'present (as an explicit keyword argument, or from another '
          'unpacking),\n'
          'a "TypeError" exception is raised.\n'
          '\n'
          'Formal parameters using the syntax "*identifier" or "**identifier"\n'
          'cannot be used as positional argument slots or as keyword argument\n'
          'names.\n'
          '\n'
          'Changed in version 3.5: Function calls accept any number of "*" '
          'and\n'
          '"**" unpackings, positional arguments may follow iterable '
          'unpackings\n'
          '("*"), and keyword arguments may follow dictionary unpackings '
          '("**").\n'
          'Originally proposed by **PEP 448**.\n'
          '\n'
          'A call always returns some value, possibly "None", unless it raises '
          'an\n'
          'exception.  How this value is computed depends on the type of the\n'
          'callable object.\n'
          '\n'
          'If it is---\n'
          '\n'
          'a user-defined function:\n'
          '   The code block for the function is executed, passing it the\n'
          '   argument list.  The first thing the code block will do is bind '
          'the\n'
          '   formal parameters to the arguments; this is described in '
          'section\n'
          '   Function definitions.  When the code block executes a "return"\n'
          '   statement, this specifies the return value of the function '
          'call.\n'
          '\n'
          'a built-in function or method:\n'
          '   The result is up to the interpreter; see Built-in Functions for '
          'the\n'
          '   descriptions of built-in functions and methods.\n'
          '\n'
          'a class object:\n'
          '   A new instance of that class is returned.\n'
          '\n'
          'a class instance method:\n'
          '   The corresponding user-defined function is called, with an '
          'argument\n'
          '   list that is one longer than the argument list of the call: the\n'
          '   instance becomes the first argument.\n'
          '\n'
          'a class instance:\n'
          '   The class must define a "__call__()" method; the effect is then '
          'the\n'
          '   same as if that method was called.\n',
 'class': '\n'
          'Class definitions\n'
          '*****************\n'
          '\n'
          'A class definition defines a class object (see section The '
          'standard\n'
          'type hierarchy):\n'
          '\n'
          '   classdef    ::= [decorators] "class" classname [inheritance] ":" '
          'suite\n'
          '   inheritance ::= "(" [argument_list] ")"\n'
          '   classname   ::= identifier\n'
          '\n'
          'A class definition is an executable statement.  The inheritance '
          'list\n'
          'usually gives a list of base classes (see Metaclasses for more\n'
          'advanced uses), so each item in the list should evaluate to a '
          'class\n'
          'object which allows subclassing.  Classes without an inheritance '
          'list\n'
          'inherit, by default, from the base class "object"; hence,\n'
          '\n'
          '   class Foo:\n'
          '       pass\n'
          '\n'
          'is equivalent to\n'
          '\n'
          '   class Foo(object):\n'
          '       pass\n'
          '\n'
          "The class's suite is then executed in a new execution frame (see\n"
          'Naming and binding), using a newly created local namespace and the\n'
          'original global namespace. (Usually, the suite contains mostly\n'
          "function definitions.)  When the class's suite finishes execution, "
          'its\n'
          'execution frame is discarded but its local namespace is saved. [4] '
          'A\n'
          'class object is then created using the inheritance list for the '
          'base\n'
          'classes and the saved local namespace for the attribute '
          'dictionary.\n'
          'The class name is bound to this class object in the original local\n'
          'namespace.\n'
          '\n'
          'The order in which attributes are defined in the class body is\n'
          'preserved in the new class\'s "__dict__".  Note that this is '
          'reliable\n'
          'only right after the class is created and only for classes that '
          'were\n'
          'defined using the definition syntax.\n'
          '\n'
          'Class creation can be customized heavily using metaclasses.\n'
          '\n'
          'Classes can also be decorated: just like when decorating '
          'functions,\n'
          '\n'
          '   @f1(arg)\n'
          '   @f2\n'
          '   class Foo: pass\n'
          '\n'
          'is roughly equivalent to\n'
          '\n'
          '   class Foo: pass\n'
          '   Foo = f1(arg)(f2(Foo))\n'
          '\n'
          'The evaluation rules for the decorator expressions are the same as '
          'for\n'
          'function decorators.  The result is then bound to the class name.\n'
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
          '\n'
          "**Programmer's note:** Variables defined in the class definition "
          'are\n'
          'class attributes; they are shared by instances.  Instance '
          'attributes\n'
          'can be set in a method with "self.name = value".  Both class and\n'
          'instance attributes are accessible through the notation '
          '""self.name"",\n'
          'and an instance attribute hides a class attribute with the same '
          'name\n'
          'when accessed in this way.  Class attributes can be used as '
          'defaults\n'
          'for instance attributes, but using mutable values there can lead '
          'to\n'
          'unexpected results.  Descriptors can be used to create instance\n'
          'variables with different implementation details.\n'
          '\n'
          'See also: **PEP 3115** - Metaclasses in Python 3 **PEP 3129** -\n'
          '  Class Decorators\n',
 'comparisons': '\n'
                'Comparisons\n'
                '***********\n'
                '\n'
                'Unlike C, all comparison operations in Python have the same '
                'priority,\n'
                'which is lower than that of any arithmetic, shifting or '
                'bitwise\n'
                'operation.  Also unlike C, expressions like "a < b < c" have '
                'the\n'
                'interpretation that is conventional in mathematics:\n'
                '\n'
                '   comparison    ::= or_expr ( comp_operator or_expr )*\n'
                '   comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "!="\n'
                '                     | "is" ["not"] | ["not"] "in"\n'
                '\n'
                'Comparisons yield boolean values: "True" or "False".\n'
                '\n'
                'Comparisons can be chained arbitrarily, e.g., "x < y <= z" '
                'is\n'
                'equivalent to "x < y and y <= z", except that "y" is '
                'evaluated only\n'
                'once (but in both cases "z" is not evaluated at all when "x < '
                'y" is\n'
                'found to be false).\n'
                '\n'
                'Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and '
                '*op1*,\n'
                '*op2*, ..., *opN* are comparison operators, then "a op1 b op2 '
                'c ... y\n'
                'opN z" is equivalent to "a op1 b and b op2 c and ... y opN '
                'z", except\n'
                'that each expression is evaluated at most once.\n'
                '\n'
                'Note that "a op1 b op2 c" doesn\'t imply any kind of '
                'comparison between\n'
                '*a* and *c*, so that, e.g., "x < y > z" is perfectly legal '
                '(though\n'
                'perhaps not pretty).\n'
                '\n'
                '\n'
                'Value comparisons\n'
                '=================\n'
                '\n'
                'The operators "<", ">", "==", ">=", "<=", and "!=" compare '
                'the values\n'
                'of two objects.  The objects do not need to have the same '
                'type.\n'
                '\n'
                'Chapter Objects, values and types states that objects have a '
                'value (in\n'
                'addition to type and identity).  The value of an object is a '
                'rather\n'
                'abstract notion in Python: For example, there is no canonical '
                'access\n'
                "method for an object's value.  Also, there is no requirement "
                'that the\n'
                'value of an object should be constructed in a particular way, '
                'e.g.\n'
                'comprised of all its data attributes. Comparison operators '
                'implement a\n'
                'particular notion of what the value of an object is.  One can '
                'think of\n'
                'them as defining the value of an object indirectly, by means '
                'of their\n'
                'comparison implementation.\n'
                '\n'
                'Because all types are (direct or indirect) subtypes of '
                '"object", they\n'
                'inherit the default comparison behavior from "object".  Types '
                'can\n'
                'customize their comparison behavior by implementing *rich '
                'comparison\n'
                'methods* like "__lt__()", described in Basic customization.\n'
                '\n'
                'The default behavior for equality comparison ("==" and "!=") '
                'is based\n'
                'on the identity of the objects.  Hence, equality comparison '
                'of\n'
                'instances with the same identity results in equality, and '
                'equality\n'
                'comparison of instances with different identities results in\n'
                'inequality.  A motivation for this default behavior is the '
                'desire that\n'
                'all objects should be reflexive (i.e. "x is y" implies "x == '
                'y").\n'
                '\n'
                'A default order comparison ("<", ">", "<=", and ">=") is not '
                'provided;\n'
                'an attempt raises "TypeError".  A motivation for this default '
                'behavior\n'
                'is the lack of a similar invariant as for equality.\n'
                '\n'
                'The behavior of the default equality comparison, that '
                'instances with\n'
                'different identities are always unequal, may be in contrast '
                'to what\n'
                'types will need that have a sensible definition of object '
                'value and\n'
                'value-based equality.  Such types will need to customize '
                'their\n'
                'comparison behavior, and in fact, a number of built-in types '
                'have done\n'
                'that.\n'
                '\n'
                'The following list describes the comparison behavior of the '
                'most\n'
                'important built-in types.\n'
                '\n'
                '* Numbers of built-in numeric types (Numeric Types --- int, '
                'float,\n'
                '  complex) and of the standard library types '
                '"fractions.Fraction" and\n'
                '  "decimal.Decimal" can be compared within and across their '
                'types,\n'
                '  with the restriction that complex numbers do not support '
                'order\n'
                '  comparison.  Within the limits of the types involved, they '
                'compare\n'
                '  mathematically (algorithmically) correct without loss of '
                'precision.\n'
                '\n'
                '  The not-a-number values "float(\'NaN\')" and '
                '"Decimal(\'NaN\')" are\n'
                '  special.  They are identical to themselves ("x is x" is '
                'true) but\n'
                '  are not equal to themselves ("x == x" is false).  '
                'Additionally,\n'
                '  comparing any number to a not-a-number value will return '
                '"False".\n'
                '  For example, both "3 < float(\'NaN\')" and "float(\'NaN\') '
                '< 3" will\n'
                '  return "False".\n'
                '\n'
                '* Binary sequences (instances of "bytes" or "bytearray") can '
                'be\n'
                '  compared within and across their types.  They compare\n'
                '  lexicographically using the numeric values of their '
                'elements.\n'
                '\n'
                '* Strings (instances of "str") compare lexicographically '
                'using the\n'
                '  numerical Unicode code points (the result of the built-in '
                'function\n'
                '  "ord()") of their characters. [3]\n'
                '\n'
                '  Strings and binary sequences cannot be directly compared.\n'
                '\n'
                '* Sequences (instances of "tuple", "list", or "range") can '
                'be\n'
                '  compared only within each of their types, with the '
                'restriction that\n'
                '  ranges do not support order comparison.  Equality '
                'comparison across\n'
                '  these types results in unequality, and ordering comparison '
                'across\n'
                '  these types raises "TypeError".\n'
                '\n'
                '  Sequences compare lexicographically using comparison of\n'
                '  corresponding elements, whereby reflexivity of the elements '
                'is\n'
                '  enforced.\n'
                '\n'
                '  In enforcing reflexivity of elements, the comparison of '
                'collections\n'
                '  assumes that for a collection element "x", "x == x" is '
                'always true.\n'
                '  Based on that assumption, element identity is compared '
                'first, and\n'
                '  element comparison is performed only for distinct '
                'elements.  This\n'
                '  approach yields the same result as a strict element '
                'comparison\n'
                '  would, if the compared elements are reflexive.  For '
                'non-reflexive\n'
                '  elements, the result is different than for strict element\n'
                '  comparison, and may be surprising:  The non-reflexive '
                'not-a-number\n'
                '  values for example result in the following comparison '
                'behavior when\n'
                '  used in a list:\n'
                '\n'
                "     >>> nan = float('NaN')\n"
                '     >>> nan is nan\n'
                '     True\n'
                '     >>> nan == nan\n'
                '     False                 <-- the defined non-reflexive '
                'behavior of NaN\n'
                '     >>> [nan] == [nan]\n'
                '     True                  <-- list enforces reflexivity and '
                'tests identity first\n'
                '\n'
                '  Lexicographical comparison between built-in collections '
                'works as\n'
                '  follows:\n'
                '\n'
                '  * For two collections to compare equal, they must be of the '
                'same\n'
                '    type, have the same length, and each pair of '
                'corresponding\n'
                '    elements must compare equal (for example, "[1,2] == '
                '(1,2)" is\n'
                '    false because the type is not the same).\n'
                '\n'
                '  * Collections that support order comparison are ordered the '
                'same\n'
                '    as their first unequal elements (for example, "[1,2,x] <= '
                '[1,2,y]"\n'
                '    has the same value as "x <= y").  If a corresponding '
                'element does\n'
                '    not exist, the shorter collection is ordered first (for '
                'example,\n'
                '    "[1,2] < [1,2,3]" is true).\n'
                '\n'
                '* Mappings (instances of "dict") compare equal if and only if '
                'they\n'
                '  have equal *(key, value)* pairs. Equality comparison of the '
                'keys and\n'
                '  elements enforces reflexivity.\n'
                '\n'
                '  Order comparisons ("<", ">", "<=", and ">=") raise '
                '"TypeError".\n'
                '\n'
                '* Sets (instances of "set" or "frozenset") can be compared '
                'within\n'
                '  and across their types.\n'
                '\n'
                '  They define order comparison operators to mean subset and '
                'superset\n'
                '  tests.  Those relations do not define total orderings (for '
                'example,\n'
                '  the two sets "{1,2}" and "{2,3}" are not equal, nor subsets '
                'of one\n'
                '  another, nor supersets of one another).  Accordingly, sets '
                'are not\n'
                '  appropriate arguments for functions which depend on total '
                'ordering\n'
                '  (for example, "min()", "max()", and "sorted()" produce '
                'undefined\n'
                '  results given a list of sets as inputs).\n'
                '\n'
                '  Comparison of sets enforces reflexivity of its elements.\n'
                '\n'
                '* Most other built-in types have no comparison methods '
                'implemented,\n'
                '  so they inherit the default comparison behavior.\n'
                '\n'
                'User-defined classes that customize their comparison behavior '
                'should\n'
                'follow some consistency rules, if possible:\n'
                '\n'
                '* Equality comparison should be reflexive. In other words, '
                'identical\n'
                '  objects should compare equal:\n'
                '\n'
                '     "x is y" implies "x == y"\n'
                '\n'
                '* Comparison should be symmetric. In other words, the '
                'following\n'
                '  expressions should have the same result:\n'
                '\n'
                '     "x == y" and "y == x"\n'
                '\n'
                '     "x != y" and "y != x"\n'
                '\n'
                '     "x < y" and "y > x"\n'
                '\n'
                '     "x <= y" and "y >= x"\n'
                '\n'
                '* Comparison should be transitive. The following '
                '(non-exhaustive)\n'
                '  examples illustrate that:\n'
                '\n'
                '     "x > y and y > z" implies "x > z"\n'
                '\n'
                '     "x < y and y <= z" implies "x < z"\n'
                '\n'
                '* Inverse comparison should result in the boolean negation. '
                'In other\n'
                '  words, the following expressions should have the same '
                'result:\n'
                '\n'
                '     "x == y" and "not x != y"\n'
                '\n'
                '     "x < y" and "not x >= y" (for total ordering)\n'
                '\n'
                '     "x > y" and "not x <= y" (for total ordering)\n'
                '\n'
                '  The last two expressions apply to totally ordered '
                'collections (e.g.\n'
                '  to sequences, but not to sets or mappings). See also the\n'
                '  "total_ordering()" decorator.\n'
                '\n'
                'Python does not enforce these consistency rules. In fact, '
                'the\n'
                'not-a-number values are an example for not following these '
                'rules.\n'
                '\n'
                '\n'
                'Membership test operations\n'
                '==========================\n'
                '\n'
                'The operators "in" and "not in" test for membership.  "x in '
                's"\n'
                'evaluates to true if *x* is a member of *s*, and false '
                'otherwise.  "x\n'
                'not in s" returns the negation of "x in s".  All built-in '
                'sequences\n'
                'and set types support this as well as dictionary, for which '
                '"in" tests\n'
                'whether the dictionary has a given key. For container types '
                'such as\n'
                'list, tuple, set, frozenset, dict, or collections.deque, the\n'
                'expression "x in y" is equivalent to "any(x is e or x == e '
                'for e in\n'
                'y)".\n'
                '\n'
                'For the string and bytes types, "x in y" is true if and only '
                'if *x* is\n'
                'a substring of *y*.  An equivalent test is "y.find(x) != '
                '-1".  Empty\n'
                'strings are always considered to be a substring of any other '
                'string,\n'
                'so """ in "abc"" will return "True".\n'
                '\n'
                'For user-defined classes which define the "__contains__()" '
                'method, "x\n'
                'in y" is true if and only if "y.__contains__(x)" is true.\n'
                '\n'
                'For user-defined classes which do not define "__contains__()" '
                'but do\n'
                'define "__iter__()", "x in y" is true if some value "z" with '
                '"x == z"\n'
                'is produced while iterating over "y".  If an exception is '
                'raised\n'
                'during the iteration, it is as if "in" raised that '
                'exception.\n'
                '\n'
                'Lastly, the old-style iteration protocol is tried: if a class '
                'defines\n'
                '"__getitem__()", "x in y" is true if and only if there is a '
                'non-\n'
                'negative integer index *i* such that "x == y[i]", and all '
                'lower\n'
                'integer indices do not raise "IndexError" exception.  (If any '
                'other\n'
                'exception is raised, it is as if "in" raised that '
                'exception).\n'
                '\n'
                'The operator "not in" is defined to have the inverse true '
                'value of\n'
                '"in".\n'
                '\n'
                '\n'
                'Identity comparisons\n'
                '====================\n'
                '\n'
                'The operators "is" and "is not" test for object identity: "x '
                'is y" is\n'
                'true if and only if *x* and *y* are the same object.  Object '
                'identity\n'
                'is determined using the "id()" function.  "x is not y" yields '
                'the\n'
                'inverse truth value. [4]\n',
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
 'compound': '\n'
             'Compound statements\n'
             '*******************\n'
             '\n'
             'Compound statements contain (groups of) other statements; they '
             'affect\n'
             'or control the execution of those other statements in some way.  '
             'In\n'
             'general, compound statements span multiple lines, although in '
             'simple\n'
             'incarnations a whole compound statement may be contained in one '
             'line.\n'
             '\n'
             'The "if", "while" and "for" statements implement traditional '
             'control\n'
             'flow constructs.  "try" specifies exception handlers and/or '
             'cleanup\n'
             'code for a group of statements, while the "with" statement '
             'allows the\n'
             'execution of initialization and finalization code around a block '
             'of\n'
             'code.  Function and class definitions are also syntactically '
             'compound\n'
             'statements.\n'
             '\n'
             "A compound statement consists of one or more 'clauses.'  A "
             'clause\n'
             "consists of a header and a 'suite.'  The clause headers of a\n"
             'particular compound statement are all at the same indentation '
             'level.\n'
             'Each clause header begins with a uniquely identifying keyword '
             'and ends\n'
             'with a colon.  A suite is a group of statements controlled by a\n'
             'clause.  A suite can be one or more semicolon-separated simple\n'
             'statements on the same line as the header, following the '
             "header's\n"
             'colon, or it can be one or more indented statements on '
             'subsequent\n'
             'lines.  Only the latter form of a suite can contain nested '
             'compound\n'
             "statements; the following is illegal, mostly because it wouldn't "
             'be\n'
             'clear to which "if" clause a following "else" clause would '
             'belong:\n'
             '\n'
             '   if test1: if test2: print(x)\n'
             '\n'
             'Also note that the semicolon binds tighter than the colon in '
             'this\n'
             'context, so that in the following example, either all or none of '
             'the\n'
             '"print()" calls are executed:\n'
             '\n'
             '   if x < y < z: print(x); print(y); print(z)\n'
             '\n'
             'Summarizing:\n'
             '\n'
             '   compound_stmt ::= if_stmt\n'
             '                     | while_stmt\n'
             '                     | for_stmt\n'
             '                     | try_stmt\n'
             '                     | with_stmt\n'
             '                     | funcdef\n'
             '                     | classdef\n'
             '                     | async_with_stmt\n'
             '                     | async_for_stmt\n'
             '                     | async_funcdef\n'
             '   suite         ::= stmt_list NEWLINE | NEWLINE INDENT '
             'statement+ DEDENT\n'
             '   statement     ::= stmt_list NEWLINE | compound_stmt\n'
             '   stmt_list     ::= simple_stmt (";" simple_stmt)* [";"]\n'
             '\n'
             'Note that statements always end in a "NEWLINE" possibly followed '
             'by a\n'
             '"DEDENT".  Also note that optional continuation clauses always '
             'begin\n'
             'with a keyword that cannot start a statement, thus there are no\n'
             'ambiguities (the \'dangling "else"\' problem is solved in Python '
             'by\n'
             'requiring nested "if" statements to be indented).\n'
             '\n'
             'The formatting of the grammar rules in the following sections '
             'places\n'
             'each clause on a separate line for clarity.\n'
             '\n'
             '\n'
             'The "if" statement\n'
             '==================\n'
             '\n'
             'The "if" statement is used for conditional execution:\n'
             '\n'
             '   if_stmt ::= "if" expression ":" suite\n'
             '               ( "elif" expression ":" suite )*\n'
             '               ["else" ":" suite]\n'
             '\n'
             'It selects exactly one of the suites by evaluating the '
             'expressions one\n'
             'by one until one is found to be true (see section Boolean '
             'operations\n'
             'for the definition of true and false); then that suite is '
             'executed\n'
             '(and no other part of the "if" statement is executed or '
             'evaluated).\n'
             'If all expressions are false, the suite of the "else" clause, '
             'if\n'
             'present, is executed.\n'
             '\n'
             '\n'
             'The "while" statement\n'
             '=====================\n'
             '\n'
             'The "while" statement is used for repeated execution as long as '
             'an\n'
             'expression is true:\n'
             '\n'
             '   while_stmt ::= "while" expression ":" suite\n'
             '                  ["else" ":" suite]\n'
             '\n'
             'This repeatedly tests the expression and, if it is true, '
             'executes the\n'
             'first suite; if the expression is false (which may be the first '
             'time\n'
             'it is tested) the suite of the "else" clause, if present, is '
             'executed\n'
             'and the loop terminates.\n'
             '\n'
             'A "break" statement executed in the first suite terminates the '
             'loop\n'
             'without executing the "else" clause\'s suite.  A "continue" '
             'statement\n'
             'executed in the first suite skips the rest of the suite and goes '
             'back\n'
             'to testing the expression.\n'
             '\n'
             '\n'
             'The "for" statement\n'
             '===================\n'
             '\n'
             'The "for" statement is used to iterate over the elements of a '
             'sequence\n'
             '(such as a string, tuple or list) or other iterable object:\n'
             '\n'
             '   for_stmt ::= "for" target_list "in" expression_list ":" '
             'suite\n'
             '                ["else" ":" suite]\n'
             '\n'
             'The expression list is evaluated once; it should yield an '
             'iterable\n'
             'object.  An iterator is created for the result of the\n'
             '"expression_list".  The suite is then executed once for each '
             'item\n'
             'provided by the iterator, in the order returned by the '
             'iterator.  Each\n'
             'item in turn is assigned to the target list using the standard '
             'rules\n'
             'for assignments (see Assignment statements), and then the suite '
             'is\n'
             'executed.  When the items are exhausted (which is immediately '
             'when the\n'
             'sequence is empty or an iterator raises a "StopIteration" '
             'exception),\n'
             'the suite in the "else" clause, if present, is executed, and the '
             'loop\n'
             'terminates.\n'
             '\n'
             'A "break" statement executed in the first suite terminates the '
             'loop\n'
             'without executing the "else" clause\'s suite.  A "continue" '
             'statement\n'
             'executed in the first suite skips the rest of the suite and '
             'continues\n'
             'with the next item, or with the "else" clause if there is no '
             'next\n'
             'item.\n'
             '\n'
             'The for-loop makes assignments to the variables(s) in the target '
             'list.\n'
             'This overwrites all previous assignments to those variables '
             'including\n'
             'those made in the suite of the for-loop:\n'
             '\n'
             '   for i in range(10):\n'
             '       print(i)\n'
             '       i = 5             # this will not affect the for-loop\n'
             '                         # because i will be overwritten with '
             'the next\n'
             '                         # index in the range\n'
             '\n'
             'Names in the target list are not deleted when the loop is '
             'finished,\n'
             'but if the sequence is empty, they will not have been assigned '
             'to at\n'
             'all by the loop.  Hint: the built-in function "range()" returns '
             'an\n'
             "iterator of integers suitable to emulate the effect of Pascal's "
             '"for i\n'
             ':= a to b do"; e.g., "list(range(3))" returns the list "[0, 1, '
             '2]".\n'
             '\n'
             'Note: There is a subtlety when the sequence is being modified by '
             'the\n'
             '  loop (this can only occur for mutable sequences, i.e. lists).  '
             'An\n'
             '  internal counter is used to keep track of which item is used '
             'next,\n'
             '  and this is incremented on each iteration.  When this counter '
             'has\n'
             '  reached the length of the sequence the loop terminates.  This '
             'means\n'
             '  that if the suite deletes the current (or a previous) item '
             'from the\n'
             '  sequence, the next item will be skipped (since it gets the '
             'index of\n'
             '  the current item which has already been treated).  Likewise, '
             'if the\n'
             '  suite inserts an item in the sequence before the current item, '
             'the\n'
             '  current item will be treated again the next time through the '
             'loop.\n'
             '  This can lead to nasty bugs that can be avoided by making a\n'
             '  temporary copy using a slice of the whole sequence, e.g.,\n'
             '\n'
             '     for x in a[:]:\n'
             '         if x < 0: a.remove(x)\n'
             '\n'
             '\n'
             'The "try" statement\n'
             '===================\n'
             '\n'
             'The "try" statement specifies exception handlers and/or cleanup '
             'code\n'
             'for a group of statements:\n'
             '\n'
             '   try_stmt  ::= try1_stmt | try2_stmt\n'
             '   try1_stmt ::= "try" ":" suite\n'
             '                 ("except" [expression ["as" identifier]] ":" '
             'suite)+\n'
             '                 ["else" ":" suite]\n'
             '                 ["finally" ":" suite]\n'
             '   try2_stmt ::= "try" ":" suite\n'
             '                 "finally" ":" suite\n'
             '\n'
             'The "except" clause(s) specify one or more exception handlers. '
             'When no\n'
             'exception occurs in the "try" clause, no exception handler is\n'
             'executed. When an exception occurs in the "try" suite, a search '
             'for an\n'
             'exception handler is started.  This search inspects the except '
             'clauses\n'
             'in turn until one is found that matches the exception.  An '
             'expression-\n'
             'less except clause, if present, must be last; it matches any\n'
             'exception.  For an except clause with an expression, that '
             'expression\n'
             'is evaluated, and the clause matches the exception if the '
             'resulting\n'
             'object is "compatible" with the exception.  An object is '
             'compatible\n'
             'with an exception if it is the class or a base class of the '
             'exception\n'
             'object or a tuple containing an item compatible with the '
             'exception.\n'
             '\n'
             'If no except clause matches the exception, the search for an '
             'exception\n'
             'handler continues in the surrounding code and on the invocation '
             'stack.\n'
             '[1]\n'
             '\n'
             'If the evaluation of an expression in the header of an except '
             'clause\n'
             'raises an exception, the original search for a handler is '
             'canceled and\n'
             'a search starts for the new exception in the surrounding code '
             'and on\n'
             'the call stack (it is treated as if the entire "try" statement '
             'raised\n'
             'the exception).\n'
             '\n'
             'When a matching except clause is found, the exception is '
             'assigned to\n'
             'the target specified after the "as" keyword in that except '
             'clause, if\n'
             "present, and the except clause's suite is executed.  All except\n"
             'clauses must have an executable block.  When the end of this '
             'block is\n'
             'reached, execution continues normally after the entire try '
             'statement.\n'
             '(This means that if two nested handlers exist for the same '
             'exception,\n'
             'and the exception occurs in the try clause of the inner handler, '
             'the\n'
             'outer handler will not handle the exception.)\n'
             '\n'
             'When an exception has been assigned using "as target", it is '
             'cleared\n'
             'at the end of the except clause.  This is as if\n'
             '\n'
             '   except E as N:\n'
             '       foo\n'
             '\n'
             'was translated to\n'
             '\n'
             '   except E as N:\n'
             '       try:\n'
             '           foo\n'
             '       finally:\n'
             '           del N\n'
             '\n'
             'This means the exception must be assigned to a different name to '
             'be\n'
             'able to refer to it after the except clause.  Exceptions are '
             'cleared\n'
             'because with the traceback attached to them, they form a '
             'reference\n'
             'cycle with the stack frame, keeping all locals in that frame '
             'alive\n'
             'until the next garbage collection occurs.\n'
             '\n'
             "Before an except clause's suite is executed, details about the\n"
             'exception are stored in the "sys" module and can be accessed '
             'via\n'
             '"sys.exc_info()". "sys.exc_info()" returns a 3-tuple consisting '
             'of the\n'
             'exception class, the exception instance and a traceback object '
             '(see\n'
             'section The standard type hierarchy) identifying the point in '
             'the\n'
             'program where the exception occurred.  "sys.exc_info()" values '
             'are\n'
             'restored to their previous values (before the call) when '
             'returning\n'
             'from a function that handled an exception.\n'
             '\n'
             'The optional "else" clause is executed if and when control flows '
             'off\n'
             'the end of the "try" clause. [2] Exceptions in the "else" clause '
             'are\n'
             'not handled by the preceding "except" clauses.\n'
             '\n'
             'If "finally" is present, it specifies a \'cleanup\' handler.  '
             'The "try"\n'
             'clause is executed, including any "except" and "else" clauses.  '
             'If an\n'
             'exception occurs in any of the clauses and is not handled, the\n'
             'exception is temporarily saved. The "finally" clause is '
             'executed.  If\n'
             'there is a saved exception it is re-raised at the end of the '
             '"finally"\n'
             'clause.  If the "finally" clause raises another exception, the '
             'saved\n'
             'exception is set as the context of the new exception. If the '
             '"finally"\n'
             'clause executes a "return" or "break" statement, the saved '
             'exception\n'
             'is discarded:\n'
             '\n'
             '   >>> def f():\n'
             '   ...     try:\n'
             '   ...         1/0\n'
             '   ...     finally:\n'
             '   ...         return 42\n'
             '   ...\n'
             '   >>> f()\n'
             '   42\n'
Loading
Loading full blame…