[Python-checkins] python/dist/src/Doc/lib libfuncs.tex, 1.175.2.8, 1.175.2.9

rhettinger@users.sourceforge.net rhettinger at users.sourceforge.net
Wed Aug 24 09:07:54 CEST 2005


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18080

Modified Files:
      Tag: release24-maint
	libfuncs.tex 
Log Message:
SF bug #1100368:  Wrong "type()" syntax in docs

Docs were missing the name/bases/dict form of type().

(Much of the wording contributed by Steven Bethard.)



Index: libfuncs.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libfuncs.tex,v
retrieving revision 1.175.2.8
retrieving revision 1.175.2.9
diff -u -d -r1.175.2.8 -r1.175.2.9
--- libfuncs.tex	23 Aug 2005 04:35:22 -0000	1.175.2.8
+++ libfuncs.tex	24 Aug 2005 07:07:44 -0000	1.175.2.9
@@ -1019,26 +1019,30 @@
 
 \begin{funcdesc}{type}{object}
   Return the type of an \var{object}.  The return value is a
-  type\obindex{type} object.  The standard module
-  \module{types}\refstmodindex{types} defines names for all built-in
-  types that don't already have built-in names.
-  For instance:
+  type\obindex{type} object.  The \function{isinstance()} built-in
+  function is recommended for testing the type of an object.
+
+  With three arguments, \function{type} functions as a constructor
+  as detailed below.
+\end{funcdesc}
+
+\begin{funcdesc}{type}{name, bases, dict}
+  Return a new type object.  This is essentially a dynamic form of the
+  \keyword{class} statement. The \var{name} string is the class name
+  and becomes the \member{__name__} attribute; the \var{bases} tuple
+  itemizes the base classes and becomes the \member{__bases__}
+  attribute; and the \var{dict} dictionary is the namespace containing
+  definitions for class body and becomes the \member{__dict__}
+  attribute.  For example, the following two statements create
+  identical \class{type} objects:
 
 \begin{verbatim}
->>> import types
->>> x = 'abc'
->>> if type(x) is str: print "It's a string"
-...
-It's a string
->>> def f(): pass
-...
->>> if type(f) is types.FunctionType: print "It's a function"
-...
-It's a function
+  >>> class X(object):
+  ...     a = 1
+  ...     
+  >>> X = type('X', (object,), dict(a=1))
 \end{verbatim}
-
-  The \function{isinstance()} built-in function is recommended for
-  testing the type of an object.
+\versionadded{2.2}          
 \end{funcdesc}
 
 \begin{funcdesc}{unichr}{i}



More information about the Python-checkins mailing list