Some further clarifications:

- func.__dict__ starts out as None until the first attribute is
  assigned, at which time, it turns into a dictionary.

- del func.__dict__ sets it back to None

- It is legal to assign None to func.__dict__; this is equivalent to
  del func.__dict__

Slight rewording to clarify the BDFL's position on special syntax.
This commit is contained in:
Barry Warsaw 2001-02-26 18:03:35 +00:00
parent 0568294565
commit f18e64ab07
1 changed files with 6 additions and 4 deletions

View File

@ -55,8 +55,10 @@ Proposal
approaches in subsequent versions of Python.
A function object's __dict__ can also be set, but only to a
dictionary object (i.e. setting __dict__ to UserDict raises a
TypeError).
dictionary object or None (e.g. setting __dict__ to UserDict
raises a TypeError). Deleting a function's __dict__ attribute is
equivalent to setting it to None. If no function attributes have
ever been set, the function's __dict__ will be None.
Examples
@ -173,8 +175,8 @@ Future Directions
# etc.
}
It isn't currently clear if special syntax is necessary or
desirable.
The BDFL is currently against any such special syntactic support
for setting arbitrary function attributes.
Dissenting Opinion