summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-01-10 09:33:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-01-10 09:33:08 (GMT)
commit6fe1299b098bc49d488ca1dd06f6557e62f76056 (patch)
treec25eff52b4af1cb749848b22f0d3aacd36c44e5d
parent114713d19451e893dc7dabea9b96d396baf7ecaf (diff)
downloadcpython-6fe1299b098bc49d488ca1dd06f6557e62f76056.zip
cpython-6fe1299b098bc49d488ca1dd06f6557e62f76056.tar.gz
cpython-6fe1299b098bc49d488ca1dd06f6557e62f76056.tar.bz2
SF bug #652888: bad documentation for the "type" builtin
Clarified that not all types are included. The OP was looking for a StaticMethodType. Also, added a note and example suggesting the use of int,str, etc. instead of IntType, StrType, etc. Renamed the crummy variable name in the example from "list" to "mylist".
-rw-r--r--Doc/lib/libtypes.tex28
1 files changed, 22 insertions, 6 deletions
diff --git a/Doc/lib/libtypes.tex b/Doc/lib/libtypes.tex
index adbec3b..8ca0911 100644
--- a/Doc/lib/libtypes.tex
+++ b/Doc/lib/libtypes.tex
@@ -1,13 +1,15 @@
\section{\module{types} ---
- Names for all built-in types}
+ Names for built-in types}
\declaremodule{standard}{types}
-\modulesynopsis{Names for all built-in types.}
+\modulesynopsis{Names for built-in types.}
-This module defines names for all object types that are used by the
-standard Python interpreter, but not for the types defined by various
-extension modules. It is safe to use \samp{from types import *} ---
+This module defines names for types some object types that are used by
+the standard Python interpreter, but not for the types defined by various
+extension modules. Also, it does not include some of the types that
+arise during processing such the \code{listiterator} type.
+It is safe to use \samp{from types import *} ---
the module does not export any names besides the ones listed here.
New names exported by future versions of this module will all end in
\samp{Type}.
@@ -17,8 +19,22 @@ their argument types, like the following:
\begin{verbatim}
from types import *
-def delete(list, item):
+def delete(mylist, item):
if type(item) is IntType:
+ del mylist[item]
+ else:
+ mylist.remove(item)
+\end{verbatim}
+
+Starting in Python 2.2, built-in factory functions such as
+\function{int()} and \function{str()} are also names for the
+corresponding types. This is now the preferred way to access
+the type instead of using the \module{types} module. Accordingly,
+the example above should be written as follows:
+
+\begin{verbatim}
+def delete(mylist, item):
+ if isinstance(item, int):
del list[item]
else:
list.remove(item)