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

Skip to content

Commit 6fe1299

Browse files
committed
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".
1 parent 114713d commit 6fe1299

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

Doc/lib/libtypes.tex

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
\section{\module{types} ---
2-
Names for all built-in types}
2+
Names for built-in types}
33

44
\declaremodule{standard}{types}
5-
\modulesynopsis{Names for all built-in types.}
5+
\modulesynopsis{Names for built-in types.}
66

77

8-
This module defines names for all object types that are used by the
9-
standard Python interpreter, but not for the types defined by various
10-
extension modules. It is safe to use \samp{from types import *} ---
8+
This module defines names for types some object types that are used by
9+
the standard Python interpreter, but not for the types defined by various
10+
extension modules. Also, it does not include some of the types that
11+
arise during processing such the \code{listiterator} type.
12+
It is safe to use \samp{from types import *} ---
1113
the module does not export any names besides the ones listed here.
1214
New names exported by future versions of this module will all end in
1315
\samp{Type}.
@@ -17,8 +19,22 @@ \section{\module{types} ---
1719

1820
\begin{verbatim}
1921
from types import *
20-
def delete(list, item):
22+
def delete(mylist, item):
2123
if type(item) is IntType:
24+
del mylist[item]
25+
else:
26+
mylist.remove(item)
27+
\end{verbatim}
28+
29+
Starting in Python 2.2, built-in factory functions such as
30+
\function{int()} and \function{str()} are also names for the
31+
corresponding types. This is now the preferred way to access
32+
the type instead of using the \module{types} module. Accordingly,
33+
the example above should be written as follows:
34+
35+
\begin{verbatim}
36+
def delete(mylist, item):
37+
if isinstance(item, int):
2238
del list[item]
2339
else:
2440
list.remove(item)

0 commit comments

Comments
 (0)