Index: Doc/reference/datamodel.rst =================================================================== --- Doc/reference/datamodel.rst (revision 86442) +++ Doc/reference/datamodel.rst (working copy) @@ -1987,7 +1987,7 @@ dictionary. That behaviour is the reason why the following code raises an exception:: - >>> class C(object): + >>> class C: ... pass ... >>> c = C() Index: Doc/reference/compound_stmts.rst =================================================================== --- Doc/reference/compound_stmts.rst (revision 86442) +++ Doc/reference/compound_stmts.rst (working copy) @@ -561,8 +561,15 @@ 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 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`), using a newly created local namespace and the original global namespace. (Usually, the suite contains mostly function definitions.) When the class's Index: Doc/whatsnew/2.2.rst =================================================================== --- Doc/whatsnew/2.2.rst (revision 86442) +++ Doc/whatsnew/2.2.rst (working copy) @@ -113,7 +113,7 @@ added so if no built-in type is suitable, you can just subclass :class:`object`:: - class C(object): + class C: def __init__ (self): ... ... @@ -195,7 +195,7 @@ passed the class of the object, but not the object itself. Static and class methods are defined like this:: - class C(object): + class C: def f(arg1, arg2): ... f = staticmethod(f) @@ -219,7 +219,7 @@ from eiffel import eiffelmethod - class C(object): + class C: def f(self, arg1, arg2): # The actual function ... @@ -339,7 +339,7 @@ define a :attr:`size` attribute that's computed, but also settable, you could write:: - class C(object): + class C: def get_size (self): result = ... computation ... return result @@ -368,7 +368,7 @@ can define a class attribute named :attr:`__slots__` to limit the legal attributes to a particular set of names. An example will make this clear:: - >>> class C(object): + >>> class C: ... __slots__ = ('template', 'name') ... >>> obj = C() Index: Doc/whatsnew/2.6.rst =================================================================== --- Doc/whatsnew/2.6.rst (revision 86442) +++ Doc/whatsnew/2.6.rst (working copy) @@ -1556,7 +1556,7 @@ for adding a getter, setter or deleter function to an existing property. You would use them like this:: - class C(object): + class C: @property def x(self): return self._x Index: Doc/howto/descriptor.rst =================================================================== --- Doc/howto/descriptor.rst (revision 86442) +++ Doc/howto/descriptor.rst (working copy) @@ -153,7 +153,7 @@ alternate approach that could do this for every attribute. However, this descriptor is useful for monitoring just a few chosen attributes:: - class RevealAccess(object): + class RevealAccess: """A data descriptor that sets and returns values normally and prints a message logging their access. """ @@ -170,7 +170,7 @@ print('Updating', self.name) self.val = val - >>> class MyClass(object): + >>> class MyClass: x = RevealAccess(10, 'var "x"') y = 5 @@ -202,7 +202,7 @@ The documentation shows a typical use to define a managed attribute ``x``:: - class C(object): + class C: def getx(self): return self.__x def setx(self, value): self.__x = value def delx(self): del self.__x @@ -211,7 +211,7 @@ To see how :func:`property` is implemented in terms of the descriptor protocol, here is a pure Python equivalent:: - class Property(object): + class Property: "Emulate PyProperty_Type() in Objects/descrobject.c" def __init__(self, fget=None, fset=None, fdel=None, doc=None): @@ -247,7 +247,7 @@ affect existing client code accessing the attribute directly. The solution is to wrap access to the value attribute in a property data descriptor:: - class Cell(object): + class Cell: . . . def getvalue(self, obj): "Recalculate cell before returning value" @@ -275,7 +275,7 @@ they are invoked from an object or a class. In pure python, it works like this:: - class Function(object): + class Function: . . . def __get__(self, obj, objtype=None): "Simulate func_descr_get() in Objects/funcobject.c" @@ -283,7 +283,7 @@ Running the interpreter shows how the function descriptor works in practice:: - >>> class D(object): + >>> class D: def f(self, x): return x @@ -355,7 +355,7 @@ Since staticmethods return the underlying function with no changes, the example calls are unexciting:: - >>> class E(object): + >>> class E: def f(x): print(x) f = staticmethod(f) @@ -368,7 +368,7 @@ Using the non-data descriptor protocol, a pure Python version of :func:`staticmethod` would look like this:: - class StaticMethod(object): + class StaticMethod: "Emulate PyStaticMethod_Type() in Objects/funcobject.c" def __init__(self, f): @@ -381,7 +381,7 @@ argument list before calling the function. This format is the same for whether the caller is an object or a class:: - >>> class E(object): + >>> class E: def f(klass, x): return klass.__name__, x f = classmethod(f) @@ -416,7 +416,7 @@ Using the non-data descriptor protocol, a pure Python version of :func:`classmethod` would look like this:: - class ClassMethod(object): + class ClassMethod: "Emulate PyClassMethod_Type() in Objects/funcobject.c" def __init__(self, f): Index: Doc/howto/sorting.rst =================================================================== --- Doc/howto/sorting.rst (revision 86442) +++ Doc/howto/sorting.rst (working copy) @@ -225,7 +225,7 @@ def cmp_to_key(mycmp): 'Convert a cmp= function into a key= function' - class K(object): + class K: def __init__(self, obj, *args): self.obj = obj def __lt__(self, other): Index: Doc/library/ctypes.rst =================================================================== --- Doc/library/ctypes.rst (revision 86442) +++ Doc/library/ctypes.rst (working copy) @@ -369,7 +369,7 @@ :attr:`_as_parameter_` attribute and uses this as the function argument. Of course, it must be one of integer, string, or bytes:: - >>> class Bottles(object): + >>> class Bottles: ... def __init__(self, number): ... self._as_parameter_ = number ... Index: Doc/library/itertools.rst =================================================================== --- Doc/library/itertools.rst (revision 86442) +++ Doc/library/itertools.rst (working copy) @@ -322,7 +322,7 @@ :func:`groupby` is equivalent to:: - class groupby(object): + class groupby: # [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 def __init__(self, iterable, key=None): Index: Doc/library/sqlite3.rst =================================================================== --- Doc/library/sqlite3.rst (revision 86442) +++ Doc/library/sqlite3.rst (working copy) @@ -710,7 +710,7 @@ This is a good approach if you write the class yourself. Let's suppose you have a class like this:: - class Point(object): + class Point: def __init__(self, x, y): self.x, self.y = x, y Index: Doc/library/multiprocessing.rst =================================================================== --- Doc/library/multiprocessing.rst (revision 86442) +++ Doc/library/multiprocessing.rst (working copy) @@ -1334,7 +1334,7 @@ from multiprocessing.managers import BaseManager - class MathsClass(object): + class MathsClass: def add(self, x, y): return x + y def mul(self, x, y): Index: Doc/library/argparse.rst =================================================================== --- Doc/library/argparse.rst (revision 86442) +++ Doc/library/argparse.rst (working copy) @@ -1312,7 +1312,7 @@ that is normally used. This can be achieved by specifying the ``namespace=`` keyword argument:: - >>> class C(object): + >>> class C: ... pass ... >>> c = C() Index: Doc/library/functions.rst =================================================================== --- Doc/library/functions.rst (revision 86442) +++ Doc/library/functions.rst (working copy) @@ -255,7 +255,7 @@ ['Struct', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from'] - >>> class Foo(object): + >>> class Foo: ... def __dir__(self): ... return ["kan", "ga", "roo"] ... @@ -871,7 +871,7 @@ function for setting, and *fdel* a function for del'ing, an attribute. Typical use is to define a managed attribute ``x``:: - class C(object): + class C: def __init__(self): self._x = None @@ -890,7 +890,7 @@ 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`:: - class Parrot(object): + class Parrot: def __init__(self): self._voltage = 100000 @@ -907,7 +907,7 @@ corresponding accessor function set to the decorated function. This is best explained with an example:: - class C(object): + class C: def __init__(self): self._x = None @@ -1211,7 +1211,7 @@ attribute. For example, the following two statements create identical :class:`type` objects: - >>> class X(object): + >>> class X: ... a = 1 ... >>> X = type('X', (object,), dict(a=1)) Index: Doc/includes/sqlite3/adapter_point_1.py =================================================================== --- Doc/includes/sqlite3/adapter_point_1.py (revision 86442) +++ Doc/includes/sqlite3/adapter_point_1.py (working copy) @@ -1,6 +1,6 @@ import sqlite3 -class Point(object): +class Point: def __init__(self, x, y): self.x, self.y = x, y Index: Doc/includes/sqlite3/converter_point.py =================================================================== --- Doc/includes/sqlite3/converter_point.py (revision 86442) +++ Doc/includes/sqlite3/converter_point.py (working copy) @@ -1,6 +1,6 @@ import sqlite3 -class Point(object): +class Point: def __init__(self, x, y): self.x, self.y = x, y Index: Doc/includes/sqlite3/adapter_point_2.py =================================================================== --- Doc/includes/sqlite3/adapter_point_2.py (revision 86442) +++ Doc/includes/sqlite3/adapter_point_2.py (working copy) @@ -1,6 +1,6 @@ import sqlite3 -class Point(object): +class Point: def __init__(self, x, y): self.x, self.y = x, y Index: Doc/includes/mp_newtype.py =================================================================== --- Doc/includes/mp_newtype.py (revision 86442) +++ Doc/includes/mp_newtype.py (working copy) @@ -12,7 +12,7 @@ ## -class Foo(object): +class Foo: def f(self): print('you called Foo.f()') def g(self):