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.)
This commit is contained in:
Raymond Hettinger 2005-08-24 07:06:25 +00:00
parent faffa15842
commit 76fb6d84d0

View File

@ -1057,26 +1057,30 @@ class C(B):
\begin{funcdesc}{type}{object} \begin{funcdesc}{type}{object}
Return the type of an \var{object}. The return value is a Return the type of an \var{object}. The return value is a
type\obindex{type} object. The standard module type\obindex{type} object. The \function{isinstance()} built-in
\module{types}\refstmodindex{types} defines names for all built-in function is recommended for testing the type of an object.
types that don't already have built-in names.
For instance: 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} \begin{verbatim}
>>> import types >>> class X(object):
>>> x = 'abc' ... a = 1
>>> if type(x) is str: print "It's a string" ...
... >>> X = type('X', (object,), dict(a=1))
It's a string
>>> def f(): pass
...
>>> if type(f) is types.FunctionType: print "It's a function"
...
It's a function
\end{verbatim} \end{verbatim}
\versionadded{2.2}
The \function{isinstance()} built-in function is recommended for
testing the type of an object.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{unichr}{i} \begin{funcdesc}{unichr}{i}