Skip to content

Commit 85eb8c1

Browse files
committed
- document bytes()
- throw out many mentions of "old-style/new-style" - add memoryview() though I somebody has to fill in the details - throw out str.decode() - throw out classobj and instanceobj
1 parent 3540ef1 commit 85eb8c1

File tree

10 files changed

+182
-321
lines changed

10 files changed

+182
-321
lines changed

Doc/c-api/concrete.rst

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,43 +2503,6 @@ Dictionary Objects
25032503
Other Objects
25042504
=============
25052505

2506-
2507-
.. _classobjects:
2508-
2509-
Class Objects
2510-
-------------
2511-
2512-
.. index:: object: class
2513-
2514-
Note that the class objects described here represent old-style classes, which
2515-
will go away in Python 3. When creating new types for extension modules, you
2516-
will want to work with type objects (section :ref:`typeobjects`).
2517-
2518-
2519-
.. ctype:: PyClassObject
2520-
2521-
The C structure of the objects used to describe built-in classes.
2522-
2523-
2524-
.. cvar:: PyObject* PyClass_Type
2525-
2526-
.. index:: single: ClassType (in module types)
2527-
2528-
This is the type object for class objects; it is the same object as
2529-
``types.ClassType`` in the Python layer.
2530-
2531-
2532-
.. cfunction:: int PyClass_Check(PyObject *o)
2533-
2534-
Return true if the object *o* is a class object, including instances of types
2535-
derived from the standard class object. Return false in all other cases.
2536-
2537-
2538-
.. cfunction:: int PyClass_IsSubclass(PyObject *klass, PyObject *base)
2539-
2540-
Return true if *klass* is a subclass of *base*. Return false in all other cases.
2541-
2542-
25432506
.. _fileobjects:
25442507

25452508
File Objects
@@ -2668,40 +2631,6 @@ change in future releases of Python.
26682631
failure; the appropriate exception will be set.
26692632

26702633

2671-
.. _instanceobjects:
2672-
2673-
Instance Objects
2674-
----------------
2675-
2676-
.. index:: object: instance
2677-
2678-
There are very few functions specific to instance objects.
2679-
2680-
2681-
.. cvar:: PyTypeObject PyInstance_Type
2682-
2683-
Type object for class instances.
2684-
2685-
2686-
.. cfunction:: int PyInstance_Check(PyObject *obj)
2687-
2688-
Return true if *obj* is an instance.
2689-
2690-
2691-
.. cfunction:: PyObject* PyInstance_New(PyObject *class, PyObject *arg, PyObject *kw)
2692-
2693-
Create a new instance of a specific class. The parameters *arg* and *kw* are
2694-
used as the positional and keyword parameters to the object's constructor.
2695-
2696-
2697-
.. cfunction:: PyObject* PyInstance_NewRaw(PyObject *class, PyObject *dict)
2698-
2699-
Create a new instance of a specific class without calling its constructor.
2700-
*class* is the class of new object. The *dict* parameter will be used as the
2701-
object's :attr:`__dict__`; if *NULL*, a new dictionary will be created for the
2702-
instance.
2703-
2704-
27052634
.. _function-objects:
27062635

27072636
Function Objects

Doc/c-api/utilities.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ return true, otherwise they return false and raise an appropriate exception.
750750
va_list rather than a variable number of arguments.
751751

752752

753+
.. XXX deprecated, will be removed
753754
.. cfunction:: int PyArg_Parse(PyObject *args, const char *format, ...)
754755

755756
Function used to deconstruct the argument lists of "old-style" functions ---

Doc/glossary.rst

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Glossary
2929
bytecode.
3030

3131
classic class
32-
Any class which does not inherit from :class:`object`. See
33-
:term:`new-style class`.
32+
One of the two flavors of classes in earlier Python versions. Since
33+
Python 3.0, there are no classic classes anymore.
3434

3535
coercion
3636
The implicit conversion of an instance of one type to another during an
@@ -58,15 +58,14 @@ Glossary
5858
it's almost certain you can safely ignore them.
5959

6060
descriptor
61-
Any *new-style* object that defines the methods :meth:`__get__`,
62-
:meth:`__set__`, or :meth:`__delete__`. When a class attribute is a
63-
descriptor, its special binding behavior is triggered upon attribute
64-
lookup. Normally, writing *a.b* looks up the object *b* in the class
65-
dictionary for *a*, but if *b* is a descriptor, the defined method gets
66-
called. Understanding descriptors is a key to a deep understanding of
67-
Python because they are the basis for many features including functions,
68-
methods, properties, class methods, static methods, and reference to super
69-
classes.
61+
An object that defines the methods :meth:`__get__`, :meth:`__set__`, or
62+
:meth:`__delete__`. When a class attribute is a descriptor, its special
63+
binding behavior is triggered upon attribute lookup. Normally, writing
64+
*a.b* looks up the object *b* in the class dictionary for *a*, but if *b*
65+
is a descriptor, the defined method gets called. Understanding
66+
descriptors is a key to a deep understanding of Python because they are
67+
the basis for many features including functions, methods, properties,
68+
class methods, static methods, and reference to super classes.
7069

7170
dictionary
7271
An associative array, where arbitrary keys are mapped to values. The use
@@ -277,11 +276,10 @@ Glossary
277276
scope. Likewise, global variables read and write to the global namespace.
278277

279278
new-style class
280-
Any class that inherits from :class:`object`. This includes all built-in
281-
types like :class:`list` and :class:`dict`. Only new-style classes can
282-
use Python's newer, versatile features like :attr:`__slots__`,
283-
descriptors, properties, :meth:`__getattribute__`, class methods, and
284-
static methods.
279+
Old name for the flavor of classes now used for all class objects. In
280+
earlier Python versions, only new-style classes could use Python's newer,
281+
versatile features like :attr:`__slots__`, descriptors, properties,
282+
:meth:`__getattribute__`, class methods, and static methods.
285283

286284
Python 3000
287285
Nickname for the next major Python version, 3.0 (coined long ago when the
@@ -294,11 +292,11 @@ Glossary
294292
implementation level to keep track of allocated memory.
295293

296294
__slots__
297-
A declaration inside a :term:`new-style class` that saves memory by
298-
pre-declaring space for instance attributes and eliminating instance
299-
dictionaries. Though popular, the technique is somewhat tricky to get
300-
right and is best reserved for rare cases where there are large numbers of
301-
instances in a memory-critical application.
295+
A declaration inside a class that saves memory by pre-declaring space for
296+
instance attributes and eliminating instance dictionaries. Though
297+
popular, the technique is somewhat tricky to get right and is best
298+
reserved for rare cases where there are large numbers of instances in a
299+
memory-critical application.
302300

303301
sequence
304302
An :term:`iterable` which supports efficient element access using integer

Doc/library/functions.rst

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,37 @@ available. They are listed here in alphabetical order.
139139
If no argument is given, this function returns :const:`False`.
140140

141141

142+
.. function:: bytes([arg[, encoding[, errors]]])
143+
144+
Return a new array of bytes. The :class:`bytes` type is a mutable sequence
145+
of integers in the range 0 <= x < 256. It has most of the usual methods of
146+
mutable sequences, described in :ref:`typesseq-mutable`, as well as a few
147+
methods borrowed from strings, described in :ref:`bytes-methods`.
148+
149+
The optional *arg* parameter can be used to initialize the array in a few
150+
different ways:
151+
152+
* If it is a *string*, you must also give the *encoding* (and optionally,
153+
*errors*) parameters; :func:`bytes` then acts like :meth:`str.encode`.
154+
155+
* If it is an *integer*, the array will have that size and will be
156+
initialized with null bytes.
157+
158+
* If it is an object conforming to the *buffer* interface, a read-only buffer
159+
of the object will be used to initialize the bytes array.
160+
161+
* If it is an *iterable*, it must be an iterable of integers in the range 0
162+
<= x < 256, which are used as the initial contents of the array.
163+
164+
Without an argument, an array of size 0 is created.
165+
166+
142167
.. function:: chr(i)
143168

144-
Return the string of one character whose Unicode codepoint is the integer *i*. For
145-
example, ``chr(97)`` returns the string ``'a'``. This is the inverse of
146-
:func:`ord`. The valid range for the argument depends how Python was
147-
configured -- it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
169+
Return the string of one character whose Unicode codepoint is the integer
170+
*i*. For example, ``chr(97)`` returns the string ``'a'``. This is the
171+
inverse of :func:`ord`. The valid range for the argument depends how Python
172+
was configured -- it may be either UCS2 [0..0xFFFF] or UCS4 [0..0x10FFFF].
148173
:exc:`ValueError` will be raised if *i* is outside that range.
149174

150175

@@ -557,15 +582,13 @@ available. They are listed here in alphabetical order.
557582

558583
.. function:: isinstance(object, classinfo)
559584

560-
Return true if the *object* argument is an instance of the *classinfo* argument,
561-
or of a (direct or indirect) subclass thereof. Also return true if *classinfo*
562-
is a type object (new-style class) and *object* is an object of that type or of
563-
a (direct or indirect) subclass thereof. If *object* is not a class instance or
564-
an object of the given type, the function always returns false. If *classinfo*
565-
is neither a class object nor a type object, it may be a tuple of class or type
566-
objects, or may recursively contain other such tuples (other sequence types are
567-
not accepted). If *classinfo* is not a class, type, or tuple of classes, types,
568-
and such tuples, a :exc:`TypeError` exception is raised.
585+
Return true if the *object* argument is an instance of the *classinfo*
586+
argument, or of a (direct or indirect) subclass thereof. If *object* is not
587+
an object of the given type, the function always returns false. If
588+
*classinfo* is not a class (type object), it may be a tuple of type objects,
589+
or may recursively contain other such tuples (other sequence types are not
590+
accepted). If *classinfo* is not a type or tuple of types and such tuples,
591+
a :exc:`TypeError` exception is raised.
569592

570593
.. versionchanged:: 2.2
571594
Support for a tuple of type information was added.
@@ -659,6 +682,13 @@ available. They are listed here in alphabetical order.
659682
Added support for the optional *key* argument.
660683

661684

685+
.. function:: memoryview(obj)
686+
687+
Return a "memory view" object created from the given argument.
688+
689+
XXX: To be documented.
690+
691+
662692
.. function:: min(iterable[, args...][key])
663693

664694
With a single argument *iterable*, return the smallest item of a non-empty
@@ -682,9 +712,13 @@ available. They are listed here in alphabetical order.
682712

683713
.. function:: object()
684714

685-
Return a new featureless object. :class:`object` is a base for all new style
686-
classes. It has the methods that are common to all instances of new style
687-
classes.
715+
Return a new featureless object. :class:`object` is a base for all classes.
716+
It has the methods that are common to all instances of Python classes.
717+
718+
.. note::
719+
720+
:class:`object` does *not* have a :attr:`__dict__`, so you can't assign
721+
arbitrary attributes to an instance of the :class:`object` class.
688722

689723
.. versionadded:: 2.2
690724

@@ -797,8 +831,7 @@ available. They are listed here in alphabetical order.
797831

798832
.. function:: property([fget[, fset[, fdel[, doc]]]])
799833

800-
Return a property attribute for new-style classes (classes that derive from
801-
:class:`object`).
834+
Return a property attribute.
802835

803836
*fget* is a function for getting an attribute value, likewise *fset* is a
804837
function for setting, and *fdel* a function for del'ing, an attribute. Typical
@@ -1023,11 +1056,12 @@ available. They are listed here in alphabetical order.
10231056

10241057
.. function:: super(type[, object-or-type])
10251058

1059+
.. XXX need to document PEP "new super"
1060+
10261061
Return the superclass of *type*. If the second argument is omitted the super
10271062
object returned is unbound. If the second argument is an object,
10281063
``isinstance(obj, type)`` must be true. If the second argument is a type,
1029-
``issubclass(type2, type)`` must be true. :func:`super` only works for new-style
1030-
classes.
1064+
``issubclass(type2, type)`` must be true.
10311065

10321066
A typical use for calling a cooperative superclass method is::
10331067

@@ -1061,23 +1095,26 @@ available. They are listed here in alphabetical order.
10611095

10621096
.. index:: object: type
10631097

1064-
Return the type of an *object*. The return value is a type object. The
1065-
:func:`isinstance` built-in function is recommended for testing the type of an
1066-
object.
1098+
Return the type of an *object*. The return value is a type object and
1099+
generally the same object as returned by ``object.__class__``.
1100+
1101+
The :func:`isinstance` built-in function is recommended for testing the type
1102+
of an object, because it takes subclasses into account.
10671103

1068-
With three arguments, :func:`type` functions as a constructor as detailed below.
1104+
With three arguments, :func:`type` functions as a constructor as detailed
1105+
below.
10691106

10701107

10711108
.. function:: type(name, bases, dict)
10721109
:noindex:
10731110

10741111
Return a new type object. This is essentially a dynamic form of the
1075-
:keyword:`class` statement. The *name* string is the class name and becomes the
1076-
:attr:`__name__` attribute; the *bases* tuple itemizes the base classes and
1077-
becomes the :attr:`__bases__` attribute; and the *dict* dictionary is the
1078-
namespace containing definitions for class body and becomes the :attr:`__dict__`
1079-
attribute. For example, the following two statements create identical
1080-
:class:`type` objects::
1112+
:keyword:`class` statement. The *name* string is the class name and becomes
1113+
the :attr:`__name__` attribute; the *bases* tuple itemizes the base classes
1114+
and becomes the :attr:`__bases__` attribute; and the *dict* dictionary is the
1115+
namespace containing definitions for class body and becomes the
1116+
:attr:`__dict__` attribute. For example, the following two statements create
1117+
identical :class:`type` objects::
10811118

10821119
>>> class X(object):
10831120
... a = 1
@@ -1128,6 +1165,7 @@ Python programmers, trainers, students and bookwriters should feel free to
11281165
bypass these functions without concerns about missing something important.
11291166

11301167

1168+
.. XXX does this go away?
11311169
.. function:: buffer(object[, offset[, size]])
11321170

11331171
The *object* argument must be an object that supports the buffer call interface

Doc/library/pickle.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ Pickling and unpickling normal class instances
416416
single: __getinitargs__() (copy protocol)
417417
single: __init__() (instance constructor)
418418

419+
.. XXX is __getinitargs__ only used with old-style classes?
420+
419421
When a pickled class instance is unpickled, its :meth:`__init__` method is
420422
normally *not* invoked. If it is desirable that the :meth:`__init__` method be
421423
called on unpickling, an old-style class can define a method

Doc/library/sqlite3.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,6 @@ Registering an adapter callable
547547
The other possibility is to create a function that converts the type to the
548548
string representation and register the function with :meth:`register_adapter`.
549549

550-
.. note::
551-
552-
The type/class to adapt must be a new-style class, i. e. it must have
553-
:class:`object` as one of its bases.
554-
555550
.. literalinclude:: ../includes/sqlite3/adapter_point_2.py
556551

557552
The :mod:`sqlite3` module has two default adapters for Python's built-in

Doc/library/stdtypes.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -682,22 +682,6 @@ the :mod:`re` module for string functions based on regular expressions.
682682
slice notation.
683683

684684

685-
.. XXX what about str.decode???
686-
.. method:: str.decode([encoding[, errors]])
687-
688-
Decode the string using the codec registered for *encoding*. *encoding*
689-
defaults to the default string encoding. *errors* may be given to set a
690-
different error handling scheme. The default is ``'strict'``, meaning that
691-
encoding errors raise :exc:`UnicodeError`. Other possible values are
692-
``'ignore'``, ``'replace'`` and any other name registered via
693-
:func:`codecs.register_error`, see section :ref:`codec-base-classes`.
694-
695-
.. versionadded:: 2.2
696-
697-
.. versionchanged:: 2.3
698-
Support for other error handling schemes added.
699-
700-
701685
.. method:: str.encode([encoding[, errors]])
702686

703687
Return an encoded version of the string. Default encoding is the current

Doc/reference/compound_stmts.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ must be given a value in the :meth:`__init__` method or in another method. Both
540540
class and instance variables are accessible through the notation
541541
"``self.name``", and an instance variable hides a class variable with the same
542542
name when accessed in this way. Class variables with immutable values can be
543-
used as defaults for instance variables. For new-style classes, descriptors can
544-
be used to create instance variables with different implementation details.
543+
used as defaults for instance variables. Descriptors can be used to create
544+
instance variables with different implementation details.
545+
546+
.. XXX add link to descriptor docs above
545547
546548
.. rubric:: Footnotes
547549

0 commit comments

Comments
 (0)