Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d51b0f21
Commit
d51b0f21
authored
Jun 18, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24314: Add links for general attributes like __name__, __dict__
parent
eb063011
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
72 additions
and
67 deletions
+72
-67
Doc/c-api/class.rst
Doc/c-api/class.rst
+1
-1
Doc/c-api/module.rst
Doc/c-api/module.rst
+2
-2
Doc/c-api/typeobj.rst
Doc/c-api/typeobj.rst
+2
-2
Doc/library/__builtin__.rst
Doc/library/__builtin__.rst
+1
-1
Doc/library/functions.rst
Doc/library/functions.rst
+5
-5
Doc/library/functools.rst
Doc/library/functools.rst
+1
-1
Doc/library/inspect.rst
Doc/library/inspect.rst
+7
-5
Doc/library/restricted.rst
Doc/library/restricted.rst
+1
-1
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+6
-4
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+31
-30
Doc/tutorial/classes.rst
Doc/tutorial/classes.rst
+2
-2
Doc/whatsnew/2.1.rst
Doc/whatsnew/2.1.rst
+2
-2
Doc/whatsnew/2.2.rst
Doc/whatsnew/2.2.rst
+7
-7
Doc/whatsnew/2.3.rst
Doc/whatsnew/2.3.rst
+4
-4
No files found.
Doc/c-api/class.rst
View file @
d51b0f21
...
@@ -61,5 +61,5 @@ There are very few functions specific to instance objects.
...
@@ -61,5 +61,5 @@ There are very few functions specific to instance objects.
Create a new instance of a specific class without calling its constructor.
Create a new instance of a specific class without calling its constructor.
*class* is the class of new object. The *dict* parameter will be used as the
*class* is the class of new object. The *dict* parameter will be used as the
object's :attr:`__dict__`; if *NULL*, a new dictionary will be created for the
object's :attr:`
~object.
__dict__`; if *NULL*, a new dictionary will be created for the
instance.
instance.
Doc/c-api/module.rst
View file @
d51b0f21
...
@@ -51,10 +51,10 @@ There are only a few functions special to module objects.
...
@@ -51,10 +51,10 @@ There are only a few functions special to module objects.
.. index:: single: __dict__ (module attribute)
.. index:: single: __dict__ (module attribute)
Return the dictionary object that implements *module*'s namespace; this object
Return the dictionary object that implements *module*'s namespace; this object
is the same as the :attr:`__dict__` attribute of the module object. This
is the same as the :attr:`
~object.
__dict__` attribute of the module object. This
function never fails. It is recommended extensions use other
function never fails. It is recommended extensions use other
:c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly
:c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly
manipulate a module's :attr:`__dict__`.
manipulate a module's :attr:`
~object.
__dict__`.
.. c:function:: char* PyModule_GetName(PyObject *module)
.. c:function:: char* PyModule_GetName(PyObject *module)
...
...
Doc/c-api/typeobj.rst
View file @
d51b0f21
...
@@ -117,10 +117,10 @@ type objects) *must* have the :attr:`ob_size` field.
...
@@ -117,10 +117,10 @@ type objects) *must* have the :attr:`ob_size` field.
For statically allocated type objects, the tp_name field should contain a dot.
For statically allocated type objects, the tp_name field should contain a dot.
Everything before the last dot is made accessible as the :attr:`__module__`
Everything before the last dot is made accessible as the :attr:`__module__`
attribute, and everything after the last dot is made accessible as the
attribute, and everything after the last dot is made accessible as the
:attr:`__name__` attribute.
:attr:`
~definition.
__name__` attribute.
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
:attr:`__name__` attribute, and the :attr:`__module__` attribute is undefined
:attr:`
~definition.
__name__` attribute, and the :attr:`__module__` attribute is undefined
(unless explicitly set in the dictionary, as explained above). This means your
(unless explicitly set in the dictionary, as explained above). This means your
type will be impossible to pickle.
type will be impossible to pickle.
...
...
Doc/library/__builtin__.rst
View file @
d51b0f21
...
@@ -39,6 +39,6 @@ that wants to implement an :func:`open` function that wraps the built-in
...
@@ -39,6 +39,6 @@ that wants to implement an :func:`open` function that wraps the built-in
Most modules have the name ``__builtins__`` (note the ``'s'``) made available
Most modules have the name ``__builtins__`` (note the ``'s'``) made available
as part of their globals. The value of ``__builtins__`` is normally either
as part of their globals. The value of ``__builtins__`` is normally either
this module or the value of this modules's :attr:`__dict__` attribute. Since
this module or the value of this modules's :attr:`
~object.
__dict__` attribute. Since
this is an implementation detail, it may not be used by alternate
this is an implementation detail, it may not be used by alternate
implementations of Python.
implementations of Python.
Doc/library/functions.rst
View file @
d51b0f21
...
@@ -311,7 +311,7 @@ section.
...
@@ -311,7 +311,7 @@ section.
:func:`dir` reports their attributes.
:func:`dir` reports their attributes.
If the object does not provide :meth:`__dir__`, the function tries its best to
If the object does not provide :meth:`__dir__`, the function tries its best to
gather information from the object's :attr:`__dict__` attribute, if defined, and
gather information from the object's :attr:`
~object.
__dict__` attribute, if defined, and
from its type object. The resulting list is not necessarily complete, and may
from its type object. The resulting list is not necessarily complete, and may
be inaccurate when the object has a custom :func:`__getattr__`.
be inaccurate when the object has a custom :func:`__getattr__`.
...
@@ -1477,7 +1477,7 @@ section.
...
@@ -1477,7 +1477,7 @@ section.
With three arguments, return a new type object. This is essentially a
With three arguments, return a new type object. This is essentially a
dynamic form of the :keyword:`class` statement. The *name* string is the
dynamic form of the :keyword:`class` statement. The *name* string is the
class name and becomes the :attr:`~
class
.__name__` attribute; the *bases* tuple
class name and becomes the :attr:`~
definition
.__name__` attribute; the *bases* tuple
itemizes the base classes and becomes the :attr:`~class.__bases__` attribute;
itemizes the base classes and becomes the :attr:`~class.__bases__` attribute;
and the *dict* dictionary is the namespace containing definitions for class
and the *dict* dictionary is the namespace containing definitions for class
body and becomes the :attr:`~object.__dict__` attribute. For example, the
body and becomes the :attr:`~object.__dict__` attribute. For example, the
...
@@ -1545,11 +1545,11 @@ section.
...
@@ -1545,11 +1545,11 @@ section.
.. function:: vars([object])
.. function:: vars([object])
Return the :attr:`~object.__dict__` attribute for a module, class, instance,
Return the :attr:`~object.__dict__` attribute for a module, class, instance,
or any other object with a :attr:`__dict__` attribute.
or any other object with a :attr:`
~object.
__dict__` attribute.
Objects such as modules and instances have an updateable :attr:`__dict__`
Objects such as modules and instances have an updateable :attr:`
~object.
__dict__`
attribute; however, other objects may have write restrictions on their
attribute; however, other objects may have write restrictions on their
:attr:`__dict__` attributes (for example, new-style classes use a
:attr:`
~object.
__dict__` attributes (for example, new-style classes use a
dictproxy to prevent direct dictionary updates).
dictproxy to prevent direct dictionary updates).
Without an argument, :func:`vars` acts like :func:`locals`. Note, the
Without an argument, :func:`vars` acts like :func:`locals`. Note, the
...
...
Doc/library/functools.rst
View file @
d51b0f21
...
@@ -185,7 +185,7 @@ have three read-only attributes:
...
@@ -185,7 +185,7 @@ have three read-only attributes:
:class:`partial` objects are like :class:`function` objects in that they are
:class:`partial` objects are like :class:`function` objects in that they are
callable, weak referencable, and can have attributes. There are some important
callable, weak referencable, and can have attributes. There are some important
differences. For instance, the :attr:`__name__` and :attr:`__doc__` attributes
differences. For instance, the :attr:`
~definition.
__name__` and :attr:`__doc__` attributes
are not created automatically. Also, :class:`partial` objects defined in
are not created automatically. Also, :class:`partial` objects defined in
classes behave like static methods and do not transform into bound methods
classes behave like static methods and do not transform into bound methods
during instance attribute look-up.
during instance attribute look-up.
...
...
Doc/library/inspect.rst
View file @
d51b0f21
...
@@ -335,9 +335,11 @@ Note:
...
@@ -335,9 +335,11 @@ Note:
are true.
are true.
This is new as of Python 2.2, and, for example, is true of
This is new as of Python 2.2, and, for example, is true of
``int.__add__``. An object passing this test has a :attr:`__get__` attribute
``int.__add__``. An object passing this test
but not a :attr:`__set__` attribute, but beyond that the set of attributes
has a :meth:`~object.__get__` method but not a :meth:`~object.__set__`
varies. :attr:`__name__` is usually sensible, and :attr:`__doc__` often is.
method, but beyond that the set of attributes varies. A
:attr:`~definition.__name__` attribute is usually
sensible, and :attr:`__doc__` often is.
Methods implemented via descriptors that also pass one of the other tests
Methods implemented via descriptors that also pass one of the other tests
return false from the :func:`ismethoddescriptor` test, simply because the
return false from the :func:`ismethoddescriptor` test, simply because the
...
@@ -349,11 +351,11 @@ Note:
...
@@ -349,11 +351,11 @@ Note:
Return true if the object is a data descriptor.
Return true if the object is a data descriptor.
Data descriptors have both a :attr:`
__get__` and a :attr:`__set__` attribute
.
Data descriptors have both a :attr:`
~object.__get__` and a :attr:`~object.__set__` method
.
Examples are properties (defined in Python), getsets, and members. The
Examples are properties (defined in Python), getsets, and members. The
latter two are defined in C and there are more specific tests available for
latter two are defined in C and there are more specific tests available for
those types, which is robust across Python implementations. Typically, data
those types, which is robust across Python implementations. Typically, data
descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes
descriptors will also have :attr:`
~definition.
__name__` and :attr:`__doc__` attributes
(properties, getsets, and members have both of these attributes), but this is
(properties, getsets, and members have both of these attributes), but this is
not guaranteed.
not guaranteed.
...
...
Doc/library/restricted.rst
View file @
d51b0f21
...
@@ -48,7 +48,7 @@ deemed to be restricted.
...
@@ -48,7 +48,7 @@ deemed to be restricted.
Python code executing in restricted mode faces a number of limitations that are
Python code executing in restricted mode faces a number of limitations that are
designed to prevent it from escaping from the padded cell. For instance, the
designed to prevent it from escaping from the padded cell. For instance, the
function object attribute :attr:`func_globals` and the class and instance object
function object attribute :attr:`func_globals` and the class and instance object
attribute :attr:`__dict__` are unavailable.
attribute :attr:`
~object.
__dict__` are unavailable.
Two modules provide the framework for setting up restricted execution
Two modules provide the framework for setting up restricted execution
environments:
environments:
...
...
Doc/library/stdtypes.rst
View file @
d51b0f21
...
@@ -2927,9 +2927,10 @@ an (external) *definition* for a module named *foo* somewhere.)
...
@@ -2927,9 +2927,10 @@ an (external) *definition* for a module named *foo* somewhere.)
A special attribute of every module is :attr:`~object.__dict__`. This is the
A special attribute of every module is :attr:`~object.__dict__`. This is the
dictionary containing the module's symbol table. Modifying this dictionary will
dictionary containing the module's symbol table. Modifying this dictionary will
actually change the module's symbol table, but direct assignment to the
actually change the module's symbol table, but direct assignment to the
:attr:`__dict__` attribute is not possible (you can write
:attr:`
~object.
__dict__` attribute is not possible (you can write
``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
``m.__dict__ = {}``). Modifying :attr:`__dict__` directly is not recommended.
``m.__dict__ = {}``). Modifying :attr:`~object.__dict__` directly is
not recommended.
Modules built into the interpreter are written like this: ``<module 'sys'
Modules built into the interpreter are written like this: ``<module 'sys'
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from
...
@@ -3156,9 +3157,10 @@ types, where they are relevant. Some of these are not reported by the
...
@@ -3156,9 +3157,10 @@ types, where they are relevant. Some of these are not reported by the
The tuple of base classes of a class object.
The tuple of base classes of a class object.
.. attribute::
class
.__name__
.. attribute::
definition
.__name__
The name of the class or type.
The name of the class, type, function, method, descriptor, or
generator instance.
The following attributes are only supported by :term:`new-style class`\ es.
The following attributes are only supported by :term:`new-style class`\ es.
...
...
Doc/reference/datamodel.rst
View file @
d51b0f21
...
@@ -481,6 +481,24 @@ Callable types
...
@@ -481,6 +481,24 @@ Callable types
.. tabularcolumns:: |l|L|l|
.. tabularcolumns:: |l|L|l|
.. index::
single: __doc__ (function attribute)
single: __name__ (function attribute)
single: __module__ (function attribute)
single: __dict__ (function attribute)
single: __defaults__ (function attribute)
single: __code__ (function attribute)
single: __globals__ (function attribute)
single: __closure__ (function attribute)
single: func_doc (function attribute)
single: func_name (function attribute)
single: func_dict (function attribute)
single: func_defaults (function attribute)
single: func_code (function attribute)
single: func_globals (function attribute)
single: func_closure (function attribute)
pair: global; namespace
+-----------------------+-------------------------------+-----------+
+-----------------------+-------------------------------+-----------+
| Attribute | Meaning | |
| Attribute | Meaning | |
+=======================+===============================+===========+
+=======================+===============================+===========+
...
@@ -488,7 +506,8 @@ Callable types
...
@@ -488,7 +506,8 @@ Callable types
| :attr:`func_doc` | string, or ``None`` if | |
| :attr:`func_doc` | string, or ``None`` if | |
| | unavailable. | |
| | unavailable. | |
+-----------------------+-------------------------------+-----------+
+-----------------------+-------------------------------+-----------+
| :attr:`__name__` | The function's name. | Writable |
| :attr:`~definition.\ | The function's name | Writable |
| __name__` | | |
| :attr:`func_name` | | |
| :attr:`func_name` | | |
+-----------------------+-------------------------------+-----------+
+-----------------------+-------------------------------+-----------+
| :attr:`__module__` | The name of the module the | Writable |
| :attr:`__module__` | The name of the module the | Writable |
...
@@ -511,9 +530,9 @@ Callable types
...
@@ -511,9 +530,9 @@ Callable types
| | module in which the function | |
| | module in which the function | |
| | was defined. | |
| | was defined. | |
+-----------------------+-------------------------------+-----------+
+-----------------------+-------------------------------+-----------+
| :attr:`
__dict__`
| The namespace supporting | Writable |
| :attr:`
~object.\
| The namespace supporting | Writable |
|
:attr:`func_dict`
| arbitrary function | |
|
__dict__`
| arbitrary function | |
|
| attributes. | |
|
:attr:`func_dict`
| attributes. | |
+-----------------------+-------------------------------+-----------+
+-----------------------+-------------------------------+-----------+
| :attr:`__closure__` | ``None`` or a tuple of cells | Read-only |
| :attr:`__closure__` | ``None`` or a tuple of cells | Read-only |
| :attr:`func_closure` | that contain bindings for the | |
| :attr:`func_closure` | that contain bindings for the | |
...
@@ -540,24 +559,6 @@ Callable types
...
@@ -540,24 +559,6 @@ Callable types
Additional information about a function's definition can be retrieved from its
Additional information about a function's definition can be retrieved from its
code object; see the description of internal types below.
code object; see the description of internal types below.
.. index::
single: __doc__ (function attribute)
single: __name__ (function attribute)
single: __module__ (function attribute)
single: __dict__ (function attribute)
single: __defaults__ (function attribute)
single: __code__ (function attribute)
single: __globals__ (function attribute)
single: __closure__ (function attribute)
single: func_doc (function attribute)
single: func_name (function attribute)
single: func_dict (function attribute)
single: func_defaults (function attribute)
single: func_code (function attribute)
single: func_globals (function attribute)
single: func_closure (function attribute)
pair: global; namespace
User-defined methods
User-defined methods
.. index::
.. index::
object: method
object: method
...
@@ -571,7 +572,7 @@ Callable types
...
@@ -571,7 +572,7 @@ Callable types
:attr:`im_func` is the function object; :attr:`im_class` is the class of
:attr:`im_func` is the function object; :attr:`im_class` is the class of
:attr:`im_self` for bound methods or the class that asked for the method for
:attr:`im_self` for bound methods or the class that asked for the method for
unbound methods; :attr:`__doc__` is the method's documentation (same as
unbound methods; :attr:`__doc__` is the method's documentation (same as
``im_func.__doc__``); :attr:`__name__` is the method name (same as
``im_func.__doc__``); :attr:`
~definition.
__name__` is the method name (same as
``im_func.__name__``); :attr:`__module__` is the name of the module the method
``im_func.__name__``); :attr:`__module__` is the name of the module the method
was defined in, or ``None`` if unavailable.
was defined in, or ``None`` if unavailable.
...
@@ -683,7 +684,7 @@ Callable types
...
@@ -683,7 +684,7 @@ Callable types
standard built-in module). The number and type of the arguments are
standard built-in module). The number and type of the arguments are
determined by the C function. Special read-only attributes:
determined by the C function. Special read-only attributes:
:attr:`__doc__` is the function's documentation string, or ``None`` if
:attr:`__doc__` is the function's documentation string, or ``None`` if
unavailable; :attr:`__name__` is the function's name; :attr:`__self__` is
unavailable; :attr:`
~definition.
__name__` is the function's name; :attr:`__self__` is
set to ``None`` (but see the next item); :attr:`__module__` is the name of
set to ``None`` (but see the next item); :attr:`__module__` is the name of
the module the function was defined in or ``None`` if unavailable.
the module the function was defined in or ``None`` if unavailable.
...
@@ -744,7 +745,7 @@ Modules
...
@@ -744,7 +745,7 @@ Modules
.. index:: single: __dict__ (module attribute)
.. index:: single: __dict__ (module attribute)
Special read-only attribute: :attr:`__dict__` is the module's namespace as a
Special read-only attribute: :attr:`
~object.
__dict__` is the module's namespace as a
dictionary object.
dictionary object.
.. impl-detail::
.. impl-detail::
...
@@ -806,7 +807,7 @@ Classes
...
@@ -806,7 +807,7 @@ Classes
static method object, it is transformed into the object wrapped by the static
static method object, it is transformed into the object wrapped by the static
method object. See section :ref:`descriptors` for another way in which
method object. See section :ref:`descriptors` for another way in which
attributes retrieved from a class may differ from those actually contained in
attributes retrieved from a class may differ from those actually contained in
its :attr:`__dict__` (note that only new-style classes support descriptors).
its :attr:`
~object.
__dict__` (note that only new-style classes support descriptors).
.. index:: triple: class; attribute; assignment
.. index:: triple: class; attribute; assignment
...
@@ -824,8 +825,8 @@ Classes
...
@@ -824,8 +825,8 @@ Classes
single: __bases__ (class attribute)
single: __bases__ (class attribute)
single: __doc__ (class attribute)
single: __doc__ (class attribute)
Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is
Special attributes: :attr:`
~definition.
__name__` is the class name; :attr:`__module__` is
the module name in which the class was defined; :attr:`__dict__` is the
the module name in which the class was defined; :attr:`
~object.
__dict__` is the
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
tuple (possibly empty or a singleton) containing the base classes, in the
tuple (possibly empty or a singleton) containing the base classes, in the
order of their occurrence in the base class list; :attr:`__doc__` is the
order of their occurrence in the base class list; :attr:`__doc__` is the
...
@@ -851,7 +852,7 @@ Class instances
...
@@ -851,7 +852,7 @@ Class instances
objects are also transformed, as if they had been retrieved from class
objects are also transformed, as if they had been retrieved from class
:class:`C`; see above under "Classes". See section :ref:`descriptors` for
:class:`C`; see above under "Classes". See section :ref:`descriptors` for
another way in which attributes of a class retrieved via its instances may
another way in which attributes of a class retrieved via its instances may
differ from the objects actually stored in the class's :attr:`__dict__`. If no
differ from the objects actually stored in the class's :attr:`
~object.
__dict__`. If no
class attribute is found, and the object's class has a :meth:`__getattr__`
class attribute is found, and the object's class has a :meth:`__getattr__`
method, that is called to satisfy the lookup.
method, that is called to satisfy the lookup.
...
@@ -1554,7 +1555,7 @@ method (a so-called *descriptor* class) appears in an *owner* class (the
...
@@ -1554,7 +1555,7 @@ method (a so-called *descriptor* class) appears in an *owner* class (the
descriptor must be in either the owner's class dictionary or in the class
descriptor must be in either the owner's class dictionary or in the class
dictionary for one of its parents). In the examples below, "the attribute"
dictionary for one of its parents). In the examples below, "the attribute"
refers to the attribute whose name is the key of the property in the owner
refers to the attribute whose name is the key of the property in the owner
class' :attr:`__dict__`.
class' :attr:`
~object.
__dict__`.
.. method:: object.__get__(self, instance, owner)
.. method:: object.__get__(self, instance, owner)
...
...
Doc/tutorial/classes.rst
View file @
d51b0f21
...
@@ -905,8 +905,8 @@ Examples::
...
@@ -905,8 +905,8 @@ Examples::
.. rubric:: Footnotes
.. rubric:: Footnotes
.. [#] Except for one thing. Module objects have a secret read-only attribute called
.. [#] Except for one thing. Module objects have a secret read-only attribute called
:attr:`__dict__` which returns the dictionary used to implement the module's
:attr:`
~object.
__dict__` which returns the dictionary used to implement the module's
namespace; the name :attr:`__dict__` is an attribute but not a global name.
namespace; the name :attr:`
~object.
__dict__` is an attribute but not a global name.
Obviously, using this violates the abstraction of namespace implementation, and
Obviously, using this violates the abstraction of namespace implementation, and
should be restricted to things like post-mortem debuggers.
should be restricted to things like post-mortem debuggers.
Doc/whatsnew/2.1.rst
View file @
d51b0f21
...
@@ -442,8 +442,8 @@ Python syntax::
...
@@ -442,8 +442,8 @@ Python syntax::
f
.
grammar
=
"A ::= B (C D)*"
f
.
grammar
=
"A ::= B (C D)*"
The
dictionary
containing
attributes
can
be
accessed
as
the
function
's
The
dictionary
containing
attributes
can
be
accessed
as
the
function
's
:attr:`
__dict__`. Unlike the :attr:`
__dict__` attribute of class instances, in
:attr:`
~object.__dict__`. Unlike the :attr:`~object.
__dict__` attribute of class instances, in
functions you can actually assign a new dictionary to :attr:`__dict__`, though
functions you can actually assign a new dictionary to :attr:`
~object.
__dict__`, though
the new value is restricted to a regular Python dictionary; you *can'
t
*
be
the new value is restricted to a regular Python dictionary; you *can'
t
*
be
tricky
and
set
it
to
a
:
class
:`
UserDict
`
instance
,
or
any
other
random
object
tricky
and
set
it
to
a
:
class
:`
UserDict
`
instance
,
or
any
other
random
object
that
behaves
like
a
mapping
.
that
behaves
like
a
mapping
.
...
...
Doc/whatsnew/2.2.rst
View file @
d51b0f21
...
@@ -157,7 +157,7 @@ attributes and methods were supported by an object. There were some informal
...
@@ -157,7 +157,7 @@ attributes and methods were supported by an object. There were some informal
conventions, such as defining :attr:`__members__` and :attr:`__methods__`
conventions, such as defining :attr:`__members__` and :attr:`__methods__`
attributes that were lists of names, but often the author of an extension type
attributes that were lists of names, but often the author of an extension type
or a class wouldn't bother to define them. You could fall back on inspecting
or a class wouldn't bother to define them. You could fall back on inspecting
the :attr:`__dict__` of an object, but when class inheritance or an arbitrary
the :attr:`
~object.
__dict__` of an object, but when class inheritance or an arbitrary
:meth:`__getattr__` hook were in use this could still be inaccurate.
:meth:`__getattr__` hook were in use this could still be inaccurate.
The one big idea underlying the new class model is that an API for describing
The one big idea underlying the new class model is that an API for describing
...
@@ -169,7 +169,7 @@ possible, as well as more exotic constructs.
...
@@ -169,7 +169,7 @@ possible, as well as more exotic constructs.
Attribute descriptors are objects that live inside class objects, and have a few
Attribute descriptors are objects that live inside class objects, and have a few
attributes of their own:
attributes of their own:
* :attr:`__name__` is the attribute's name.
* :attr:`
~definition.
__name__` is the attribute's name.
* :attr:`__doc__` is the attribute's docstring.
* :attr:`__doc__` is the attribute's docstring.
...
@@ -329,7 +329,7 @@ However, Python 2.2's support for :dfn:`properties` will often be a simpler way
...
@@ -329,7 +329,7 @@ However, Python 2.2's support for :dfn:`properties` will often be a simpler way
to trap attribute references. Writing a :meth:`__getattr__` method is
to trap attribute references. Writing a :meth:`__getattr__` method is
complicated because to avoid recursion you can't use regular attribute accesses
complicated because to avoid recursion you can't use regular attribute accesses
inside them, and instead have to mess around with the contents of
inside them, and instead have to mess around with the contents of
:attr:`__dict__`. :meth:`__getattr__` methods also end up being called by Python
:attr:`
~object.
__dict__`. :meth:`__getattr__` methods also end up being called by Python
when it checks for other methods such as :meth:`__repr__` or :meth:`__coerce__`,
when it checks for other methods such as :meth:`__repr__` or :meth:`__coerce__`,
and so have to be written with this in mind. Finally, calling a function on
and so have to be written with this in mind. Finally, calling a function on
every attribute access results in a sizable performance loss.
every attribute access results in a sizable performance loss.
...
@@ -357,15 +357,15 @@ write::
...
@@ -357,15 +357,15 @@ write::
That is certainly clearer and easier to write than a pair of
That is certainly clearer and easier to write than a pair of
:meth:`__getattr__`/:meth:`__setattr__` methods that check for the :attr:`size`
:meth:`__getattr__`/:meth:`__setattr__` methods that check for the :attr:`size`
attribute and handle it specially while retrieving all other attributes from the
attribute and handle it specially while retrieving all other attributes from the
instance's :attr:`__dict__`. Accesses to :attr:`size` are also the only ones
instance's :attr:`
~object.
__dict__`. Accesses to :attr:`size` are also the only ones
which have to perform the work of calling a function, so references to other
which have to perform the work of calling a function, so references to other
attributes run at their usual speed.
attributes run at their usual speed.
Finally, it's possible to constrain the list of attributes that can be
Finally, it's possible to constrain the list of attributes that can be
referenced on an object using the new :attr:`__slots__` class attribute. Python
referenced on an object using the new :attr:`
~object.
__slots__` class attribute. Python
objects are usually very dynamic; at any time it's possible to define a new
objects are usually very dynamic; at any time it's possible to define a new
attribute on an instance by just doing ``obj.new_attr=1``. A new-style class
attribute on an instance by just doing ``obj.new_attr=1``. A new-style class
can define a class attribute named :attr:`__slots__` to limit the legal
can define a class attribute named :attr:`
~object.
__slots__` to limit the legal
attributes to a particular set of names. An example will make this clear::
attributes to a particular set of names. An example will make this clear::
>>> class C(object):
>>> class C(object):
...
@@ -383,7 +383,7 @@ attributes to a particular set of names. An example will make this clear::
...
@@ -383,7 +383,7 @@ attributes to a particular set of names. An example will make this clear::
AttributeError: 'C' object has no attribute 'newattr'
AttributeError: 'C' object has no attribute 'newattr'
Note how you get an :exc:`AttributeError` on the attempt to assign to an
Note how you get an :exc:`AttributeError` on the attempt to assign to an
attribute not listed in :attr:`__slots__`.
attribute not listed in :attr:`
~object.
__slots__`.
.. _sect-rellinks:
.. _sect-rellinks:
...
...
Doc/whatsnew/2.3.rst
View file @
d51b0f21
...
@@ -1111,10 +1111,10 @@ Here are all of the changes that Python 2.3 makes to the core Python language.
...
@@ -1111,10 +1111,10 @@ Here are all of the changes that Python 2.3 makes to the core Python language.
<type '_socket.socket'>
<type '_socket.socket'>
* One of the noted incompatibilities between old- and new-style classes has been
* One of the noted incompatibilities between old- and new-style classes has been
removed: you can now assign to the :attr:`
__name__` and :attr:`
__bases__`
removed: you can now assign to the :attr:`
~definition.__name__` and :attr:`~class.
__bases__`
attributes of new-style classes. There are some restrictions on what can be
attributes of new-style classes. There are some restrictions on what can be
assigned to :attr:`__bases__` along the lines of those relating to assigning to
assigned to :attr:`
~class.
__bases__` along the lines of those relating to assigning to
an instance's :attr:`__class__` attribute.
an instance's :attr:`
~instance.
__class__` attribute.
.. ======================================================================
.. ======================================================================
...
@@ -1920,7 +1920,7 @@ Changes to Python's build process and to the C API include:
...
@@ -1920,7 +1920,7 @@ Changes to Python's build process and to the C API include:
* If you dynamically allocate type objects in your extension, you should be
* If you dynamically allocate type objects in your extension, you should be
aware of a change in the rules relating to the :attr:`__module__` and
aware of a change in the rules relating to the :attr:`__module__` and
:attr:`__name__` attributes. In summary, you will want to ensure the type's
:attr:`
~definition.
__name__` attributes. In summary, you will want to ensure the type's
dictionary contains a ``'__module__'`` key; making the module name the part of
dictionary contains a ``'__module__'`` key; making the module name the part of
the type name leading up to the final period will no longer have the desired
the type name leading up to the final period will no longer have the desired
effect. For more detail, read the API reference documentation or the source.
effect. For more detail, read the API reference documentation or the source.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment