Commit 5ef99a0b authored by Barry Warsaw's avatar Barry Warsaw

Describe the new semantics for setting and deleting a function's

__dict__ attribute.  Deleting it, or setting it to a non-dictionary
result in a TypeError.  Note that getting it the first time magically
initializes it to an empty dict so that func.__dict__ will always
appear to be a dictionary (never None).

Closes SF bug #446645.
parent 680cabb2
...@@ -1047,19 +1047,14 @@ Function objects also support getting and setting arbitrary ...@@ -1047,19 +1047,14 @@ Function objects also support getting and setting arbitrary
attributes, which can be used to, e.g. attach metadata to functions. attributes, which can be used to, e.g. attach metadata to functions.
Regular attribute dot-notation is used to get and set such Regular attribute dot-notation is used to get and set such
attributes. \emph{Note that the current implementation only supports attributes. \emph{Note that the current implementation only supports
function attributes on functions written in Python. Function function attributes on user-defined functions. Function attributes on
attributes on built-ins may be supported in the future.} built-in functions may be supported in the future.}
Functions have another special attribute \code{\var{f}.__dict__} Functions have another special attribute \code{\var{f}.__dict__}
(a.k.a. \code{\var{f}.func_dict}) which contains the namespace used to (a.k.a. \code{\var{f}.func_dict}) which contains the namespace used to
support function attributes. \code{__dict__} can be accessed support function attributes. \code{__dict__} and \code{func_dict} can
directly, set to a dictionary object, or \code{None}. It can also be be accessed directly or set to a dictionary object. A function's
deleted (but the following two lines are equivalent): dictionary cannot be deleted.
\begin{verbatim}
del func.__dict__
func.__dict__ = None
\end{verbatim}
\subsubsection{Methods \label{typesmethods}} \subsubsection{Methods \label{typesmethods}}
\obindex{method} \obindex{method}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment