Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aaec403

Browse files
committed
added index entries for __*__ identifiers
1 parent 3aca2a1 commit aaec403

6 files changed

Lines changed: 130 additions & 0 deletions

File tree

Doc/ref/ref3.tex

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ \section{Special method names} \label{specialnames}
585585
class, then \verb@x[i]@ is equivalent to \verb@x.__getitem__(i)@.
586586
(The reverse is not true --- if \verb@x@ is a list object,
587587
\verb@x.__getitem__(i)@ is not equivalent to \verb@x[i]@.)
588+
\ttindex{__getitem__}
588589

589590
Except for \verb@__repr__@, \verb@__str__@ and \verb@__cmp__@,
590591
attempts to execute an
@@ -594,6 +595,9 @@ \section{Special method names} \label{specialnames}
594595
For \verb@__cmp__@, the default is to compare instances based on their
595596
address.
596597
For \verb@__str__@, the default is to use \verb@__repr__@.
598+
\ttindex{__repr__}
599+
\ttindex{__str__}
600+
\ttindex{__cmp__}
597601

598602

599603
\subsection{Special methods for any type}
@@ -606,6 +610,9 @@ \subsection{Special methods for any type}
606610
\code{__init__} method the derived class's \code{__init__} method must
607611
explicitly call it to ensure proper initialization of the base class
608612
part of the instance.
613+
\ttindex{__init__}
614+
\indexii{class}{constructor}
615+
609616

610617
\item[{\tt __del__(self)}]
611618
Called when the instance is about to be destroyed. If a base class
@@ -617,6 +624,8 @@ \subsection{Special methods for any type}
617624
reference is deleted. It is not guaranteed that
618625
\code{__del__} methods are called for objects that still exist when
619626
the interpreter exits.
627+
\ttindex{__del__}
628+
\stindex{del}
620629

621630
Note that \code{del x} doesn't directly call \code{x.__del__} --- the
622631
former decrements the reference count for \code{x} by one, but
@@ -625,6 +634,8 @@ \subsection{Special methods for any type}
625634
\item[{\tt __repr__(self)}]
626635
Called by the \verb@repr()@ built-in function and by string conversions
627636
(reverse or backward quotes) to compute the string representation of an object.
637+
\ttindex{__repr__}
638+
\bifuncindex{repr}
628639
\indexii{string}{conversion}
629640
\indexii{reverse}{quotes}
630641
\indexii{backward}{quotes}
@@ -633,6 +644,9 @@ \subsection{Special methods for any type}
633644
\item[{\tt __str__(self)}]
634645
Called by the \verb@str()@ built-in function and by the \verb@print@
635646
statement compute the string representation of an object.
647+
\ttindex{__str__}
648+
\bifuncindex{str}
649+
\stindex{print}
636650

637651
\item[{\tt __cmp__(self, other)}]
638652
Called by all comparison operations. Should return -1 if
@@ -642,6 +656,9 @@ \subsection{Special methods for any type}
642656
(Implementation note: due to limitations in the interpreter,
643657
exceptions raised by comparisons are ignored, and the objects will be
644658
considered equal in this case.)
659+
\ttindex{__cmp__}
660+
\bifuncindex{cmp}
661+
\index{comparisons}
645662

646663
\item[{\tt __hash__(self)}]
647664
Called for the key object for dictionary operations,
@@ -659,9 +676,14 @@ \subsection{Special methods for any type}
659676
\code{__hash__}, since the dictionary implementation assumes that a
660677
key's hash value is a constant.
661678
\obindex{dictionary}
679+
\ttindex{__cmp__}
680+
\ttindex{__hash__}
681+
\bifuncindex{hash}
662682

663683
\item[{\tt __call__(self, *args)}]
664684
Called when the instance is ``called'' as a function.
685+
\ttindex{__call__}
686+
\indexii{call}{instance}
665687

666688
\end{description}
667689

@@ -677,6 +699,7 @@ \subsection{Special methods for attribute access}
677699
Called when an attribute lookup has not found the attribute in the
678700
usual places (i.e. it is not an instance attribute nor is it found in
679701
the class tree for \code{self}). \code{name} is the attribute name.
702+
\ttindex{__getattr__}
680703

681704
Note that if the attribute is found through the normal mechanism,
682705
\code{__getattr__} is not called. (This is an asymmetry between
@@ -687,22 +710,26 @@ \subsection{Special methods for attribute access}
687710
Note that at least for instance variables, \code{__getattr__} can fake
688711
total control by simply not inserting any values in the instance
689712
attribute dictionary.
713+
\ttindex{__setattr__}
690714

691715
\item[{\tt __setattr__(self, name, value)}]
692716
Called when an attribute assignment is attempted. This is called
693717
instead of the normal mechanism (i.e. store the value as an instance
694718
attribute). \code{name} is the attribute name, \code{value} is the
695719
value to be assigned to it.
720+
\ttindex{__setattr__}
696721

697722
If \code{__setattr__} wants to assign to an instance attribute, it
698723
should not simply execute \code{self.\var{name} = value} --- this would
699724
cause a recursive call. Instead, it should insert the value in the
700725
dictionary of instance attributes, e.g. \code{self.__dict__[name] =
701726
value}.
727+
\ttindex{__dict__}
702728

703729
\item[{\tt __delattr__(self, name)}]
704730
Like \code{__setattr__} but for attribute deletion instead of
705731
assignment.
732+
\ttindex{__delattr__}
706733

707734
\end{description}
708735

@@ -716,19 +743,23 @@ \subsection{Special methods for sequence and mapping types}
716743
the length of the object, an integer \verb@>=@ 0. Also, an object
717744
whose \verb@__len__()@ method returns 0 is considered to be false in a
718745
Boolean context.
746+
\ttindex{__len__}
719747

720748
\item[{\tt __getitem__(self, key)}]
721749
Called to implement evaluation of \verb@self[key]@. Note that the
722750
special interpretation of negative keys (if the class wishes to
723751
emulate a sequence type) is up to the \verb@__getitem__@ method.
752+
\ttindex{__getitem__}
724753

725754
\item[{\tt __setitem__(self, key, value)}]
726755
Called to implement assignment to \verb@self[key]@. Same note as for
727756
\verb@__getitem__@.
757+
\ttindex{__setitem__}
728758

729759
\item[{\tt __delitem__(self, key)}]
730760
Called to implement deletion of \verb@self[key]@. Same note as for
731761
\verb@__getitem__@.
762+
\ttindex{__delitem__}
732763

733764
\end{description}
734765

@@ -743,14 +774,17 @@ \subsection{Special methods for sequence types}
743774
respectively, and \verb@len(self)@ has been added (once) to originally
744775
negative \verb@i@ or \verb@j@ by the time this function is called
745776
(unlike for \verb@__getitem__@).
777+
\ttindex{__getslice__}
746778

747779
\item[{\tt __setslice__(self, i, j, sequence)}]
748780
Called to implement assignment to \verb@self[i:j]@. Same notes as for
749781
\verb@__getslice__@.
782+
\ttindex{__setslice__}
750783

751784
\item[{\tt __delslice__(self, i, j)}]
752785
Called to implement deletion of \verb@self[i:j]@. Same notes as for
753786
\verb@__getslice__@.
787+
\ttindex{__delslice__}
754788

755789
\end{description}
756790

@@ -774,17 +808,34 @@ \subsection{Special methods for numeric types}
774808
Called to implement the binary arithmetic operations (\verb@+@,
775809
\verb@-@, \verb@*@, \verb@/@, \verb@%@, \verb@divmod()@, \verb@pow()@,
776810
\verb@<<@, \verb@>>@, \verb@&@, \verb@^@, \verb@|@).
811+
\ttindex{__or__}
812+
\ttindex{__xor__}
813+
\ttindex{__and__}
814+
\ttindex{__rshift__}
815+
\ttindex{__lshift__}
816+
\ttindex{__pow__}
817+
\ttindex{__divmod__}
818+
\ttindex{__mod__}
819+
\ttindex{__div__}
820+
\ttindex{__mul__}
821+
\ttindex{__sub__}
822+
\ttindex{__add__}
777823

778824
\item[{\tt __neg__(self)}]\itemjoin
779825
\item[{\tt __pos__(self)}]\itemjoin
780826
\item[{\tt __abs__(self)}]\itemjoin
781827
\item[{\tt __invert__(self)}]\itembreak
782828
Called to implement the unary arithmetic operations (\verb@-@, \verb@+@,
783829
\verb@abs()@ and \verb@~@).
830+
\ttindex{__invert__}
831+
\ttindex{__abs__}
832+
\ttindex{__pos__}
833+
\ttindex{__neg__}
784834

785835
\item[{\tt __nonzero__(self)}]
786836
Called to implement boolean testing; should return 0 or 1. An
787837
alternative name for this method is \verb@__len__@.
838+
\ttindex{__nonzero__}
788839

789840
\item[{\tt __coerce__(self, other)}]
790841
Called to implement ``mixed-mode'' numeric arithmetic. Should either
@@ -794,6 +845,7 @@ \subsection{Special methods for numeric types}
794845
interpreter will also ask the other object to attempt a coercion (but
795846
sometimes, if the implementation of the other type cannot be changed,
796847
it is useful to do the conversion to the other type here).
848+
\ttindex{__coerce__}
797849

798850
Note that this method is not called to coerce the arguments to \verb@+@
799851
and \verb@*@, because these are also used to implement sequence
@@ -803,16 +855,22 @@ \subsection{Special methods for numeric types}
803855
\footnote{The interpreter should really distinguish between
804856
user-defined classes implementing sequences, mappings or numbers, but
805857
currently it doesn't --- hence this strange exception.}
858+
\ttindex{__mul__}
806859

807860
\item[{\tt __int__(self)}]\itemjoin
808861
\item[{\tt __long__(self)}]\itemjoin
809862
\item[{\tt __float__(self)}]\itembreak
810863
Called to implement the built-in functions \verb@int()@, \verb@long()@
811864
and \verb@float()@. Should return a value of the appropriate type.
865+
\ttindex{__float__}
866+
\ttindex{__long__}
867+
\ttindex{__int__}
812868

813869
\item[{\tt __oct__(self)}]\itemjoin
814870
\item[{\tt __hex__(self)}]\itembreak
815871
Called to implement the built-in functions \verb@oct()@ and
816872
\verb@hex()@. Should return a string value.
873+
\ttindex{__hex__}
874+
\ttindex{__oct__}
817875

818876
\end{description}

Doc/ref/ref4.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ \section{Code blocks, execution frames, and name spaces} \label{execframes}
7777
explicitly mentioned in a {\tt global} statement change subtly: name
7878
lookup first searches the local name space, then the global one, then
7979
the built-in one.}
80+
\bimodindex{__builtin__}
81+
\stindex{from}
82+
\stindex{exec}
83+
\stindex{global}
84+
\ttindex{NameError}
8085

8186
The following table lists the meaning of the local and global name
8287
space for various types of code blocks. The name space for a
@@ -107,6 +112,7 @@ \section{Code blocks, execution frames, and name spaces} \label{execframes}
107112
\hline
108113
\end{tabular}
109114
\end{center}
115+
\bimodindex{__main__}
110116

111117
Notes:
112118

Doc/ref/ref8.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ \section{Complete Python programs}
3131
is identical to that of a complete program; each statement is executed
3232
in the name space of \verb@__main__@.
3333
\index{interactive mode}
34+
\bimodindex{__main__}
3435

3536
Under {\UNIX}, a complete program can be passed to the interpreter in
3637
three forms: with the {\bf -c} {\it string} command line option, as a

0 commit comments

Comments
 (0)