Kaydet (Commit) 28053fb1 authored tarafından Éric Araujo's avatar Éric Araujo

Remove unnecessary `object` base class in docs (#10366).

Also add a note about inheritance from `object` being default.
üst d4bbab27
...@@ -12,7 +12,7 @@ import operator ...@@ -12,7 +12,7 @@ import operator
## ##
class Foo(object): class Foo:
def f(self): def f(self):
print('you called Foo.f()') print('you called Foo.f()')
def g(self): def g(self):
......
import sqlite3 import sqlite3
class Point(object): class Point:
def __init__(self, x, y): def __init__(self, x, y):
self.x, self.y = x, y self.x, self.y = x, y
......
import sqlite3 import sqlite3
class Point(object): class Point:
def __init__(self, x, y): def __init__(self, x, y):
self.x, self.y = x, y self.x, self.y = x, y
......
import sqlite3 import sqlite3
class Point(object): class Point:
def __init__(self, x, y): def __init__(self, x, y):
self.x, self.y = x, y self.x, self.y = x, y
......
...@@ -1312,7 +1312,7 @@ already existing object, rather than the newly-created :class:`Namespace` object ...@@ -1312,7 +1312,7 @@ already existing object, rather than the newly-created :class:`Namespace` object
that is normally used. This can be achieved by specifying the ``namespace=`` that is normally used. This can be achieved by specifying the ``namespace=``
keyword argument:: keyword argument::
>>> class C(object): >>> class C:
... pass ... pass
... ...
>>> c = C() >>> c = C()
......
...@@ -369,7 +369,7 @@ your own classes be used as function arguments. :mod:`ctypes` looks for an ...@@ -369,7 +369,7 @@ your own classes be used as function arguments. :mod:`ctypes` looks for an
:attr:`_as_parameter_` attribute and uses this as the function argument. Of :attr:`_as_parameter_` attribute and uses this as the function argument. Of
course, it must be one of integer, string, or bytes:: course, it must be one of integer, string, or bytes::
>>> class Bottles(object): >>> class Bottles:
... def __init__(self, number): ... def __init__(self, number):
... self._as_parameter_ = number ... self._as_parameter_ = number
... ...
......
...@@ -259,7 +259,7 @@ are always available. They are listed here in alphabetical order. ...@@ -259,7 +259,7 @@ are always available. They are listed here in alphabetical order.
['Struct', '__builtins__', '__doc__', '__file__', '__name__', ['Struct', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
'unpack', 'unpack_from'] 'unpack', 'unpack_from']
>>> class Foo(object): >>> class Foo:
... def __dir__(self): ... def __dir__(self):
... return ["kan", "ga", "roo"] ... return ["kan", "ga", "roo"]
... ...
...@@ -903,7 +903,7 @@ are always available. They are listed here in alphabetical order. ...@@ -903,7 +903,7 @@ are always available. They are listed here in alphabetical order.
function for setting, and *fdel* a function for del'ing, an attribute. Typical function for setting, and *fdel* a function for del'ing, an attribute. Typical
use is to define a managed attribute ``x``:: use is to define a managed attribute ``x``::
class C(object): class C:
def __init__(self): def __init__(self):
self._x = None self._x = None
...@@ -922,7 +922,7 @@ are always available. They are listed here in alphabetical order. ...@@ -922,7 +922,7 @@ are always available. They are listed here in alphabetical order.
property will copy *fget*'s docstring (if it exists). This makes it possible to property will copy *fget*'s docstring (if it exists). This makes it possible to
create read-only properties easily using :func:`property` as a :term:`decorator`:: create read-only properties easily using :func:`property` as a :term:`decorator`::
class Parrot(object): class Parrot:
def __init__(self): def __init__(self):
self._voltage = 100000 self._voltage = 100000
...@@ -939,7 +939,7 @@ are always available. They are listed here in alphabetical order. ...@@ -939,7 +939,7 @@ are always available. They are listed here in alphabetical order.
corresponding accessor function set to the decorated function. This is corresponding accessor function set to the decorated function. This is
best explained with an example:: best explained with an example::
class C(object): class C:
def __init__(self): def __init__(self):
self._x = None self._x = None
...@@ -1243,7 +1243,7 @@ are always available. They are listed here in alphabetical order. ...@@ -1243,7 +1243,7 @@ are always available. They are listed here in alphabetical order.
attribute. For example, the following two statements create identical attribute. For example, the following two statements create identical
:class:`type` objects: :class:`type` objects:
>>> class X(object): >>> class X:
... a = 1 ... a = 1
... ...
>>> X = type('X', (object,), dict(a=1)) >>> X = type('X', (object,), dict(a=1))
......
...@@ -604,7 +604,7 @@ for arbitrary getset descriptors invoking these may trigger ...@@ -604,7 +604,7 @@ for arbitrary getset descriptors invoking these may trigger
code execution:: code execution::
# example code for resolving the builtin descriptor types # example code for resolving the builtin descriptor types
class _foo(object): class _foo:
__slots__ = ['foo'] __slots__ = ['foo']
slot_descriptor = type(_foo.foo) slot_descriptor = type(_foo.foo)
......
...@@ -322,7 +322,7 @@ loops that truncate the stream. ...@@ -322,7 +322,7 @@ loops that truncate the stream.
:func:`groupby` is equivalent to:: :func:`groupby` is equivalent to::
class groupby(object): class groupby:
# [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B # [k for k, g in groupby('AAAABBBCCDAABBB')] --> A B C D A B
# [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D # [list(g) for k, g in groupby('AAAABBBCCD')] --> AAAA BBB CC D
def __init__(self, iterable, key=None): def __init__(self, iterable, key=None):
......
...@@ -1334,7 +1334,7 @@ callables with the manager class. For example:: ...@@ -1334,7 +1334,7 @@ callables with the manager class. For example::
from multiprocessing.managers import BaseManager from multiprocessing.managers import BaseManager
class MathsClass(object): class MathsClass:
def add(self, x, y): def add(self, x, y):
return x + y return x + y
def mul(self, x, y): def mul(self, x, y):
......
...@@ -710,7 +710,7 @@ Letting your object adapt itself ...@@ -710,7 +710,7 @@ Letting your object adapt itself
This is a good approach if you write the class yourself. Let's suppose you have This is a good approach if you write the class yourself. Let's suppose you have
a class like this:: a class like this::
class Point(object): class Point:
def __init__(self, x, y): def __init__(self, x, y):
self.x, self.y = x, y self.x, self.y = x, y
......
...@@ -561,7 +561,16 @@ A class definition defines a class object (see section :ref:`types`): ...@@ -561,7 +561,16 @@ A class definition defines a class object (see section :ref:`types`):
A class definition is an executable statement. The inheritance list usually A class definition is an executable statement. The inheritance list usually
gives a list of base classes (see :ref:`metaclasses` for more advanced uses), so gives a list of base classes (see :ref:`metaclasses` for more advanced uses), so
each item in the list should evaluate to a class object which allows each item in the list should evaluate to a class object which allows
subclassing. subclassing. Classes without an inheritance list inherit, by default, from the
base class :class:`object`; hence, ::
class Foo:
pass
is equivalent to ::
class Foo(object):
pass
The class's suite is then executed in a new execution frame (see :ref:`naming`), The class's suite is then executed in a new execution frame (see :ref:`naming`),
using a newly created local namespace and the original global namespace. using a newly created local namespace and the original global namespace.
......
...@@ -1987,7 +1987,7 @@ to work correctly if defined on an object's type, not in the object's instance ...@@ -1987,7 +1987,7 @@ to work correctly if defined on an object's type, not in the object's instance
dictionary. That behaviour is the reason why the following code raises an dictionary. That behaviour is the reason why the following code raises an
exception:: exception::
>>> class C(object): >>> class C:
... pass ... pass
... ...
>>> c = C() >>> c = C()
......
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