diff -r 9f464eff218a Doc/howto/descriptor.rst --- a/Doc/howto/descriptor.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/howto/descriptor.rst Mon Mar 04 14:21:45 2013 +0000 @@ -145,7 +145,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. """ @@ -162,7 +162,7 @@ print('Updating', self.name) self.val = val - >>> class MyClass(object): + >>> class MyClass: x = RevealAccess(10, 'var "x"') y = 5 @@ -194,7 +194,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 @@ -203,7 +203,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): @@ -216,17 +216,17 @@ if obj is None: return self if self.fget is None: - raise AttributeError, "unreadable attribute" + raise AttributeError("unreadable attribute") return self.fget(obj) def __set__(self, obj, value): if self.fset is None: - raise AttributeError, "can't set attribute" + raise AttributeError("can't set attribute") self.fset(obj, value) def __delete__(self, obj): if self.fdel is None: - raise AttributeError, "can't delete attribute" + raise AttributeError("can't delete attribute") self.fdel(obj) The :func:`property` builtin helps whenever a user interface has granted @@ -239,7 +239,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" @@ -267,7 +267,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" @@ -275,7 +275,7 @@ Running the interpreter shows how the function descriptor works in practice:: - >>> class D(object): + >>> class D: def f(self, x): return x @@ -347,7 +347,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) @@ -360,7 +360,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): @@ -373,7 +373,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) @@ -408,7 +408,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): diff -r 9f464eff218a Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/howto/logging-cookbook.rst Mon Mar 04 14:21:45 2013 +0000 @@ -1036,7 +1036,7 @@ call ``str()`` on that object to get the actual format string. Consider the following two classes:: - class BraceMessage(object): + class BraceMessage: def __init__(self, fmt, *args, **kwargs): self.fmt = fmt self.args = args @@ -1045,7 +1045,7 @@ def __str__(self): return self.fmt.format(*self.args, **self.kwargs) - class DollarMessage(object): + class DollarMessage: def __init__(self, fmt, **kwargs): self.fmt = fmt self.kwargs = kwargs @@ -1372,7 +1372,7 @@ import random import time - class MyHandler(object): + class MyHandler: """ A simple handler for logging events. It runs in the listener process and dispatches events to loggers based on the name in the received record, diff -r 9f464eff218a Doc/howto/sorting.rst --- a/Doc/howto/sorting.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/howto/sorting.rst Mon Mar 04 14:21:45 2013 +0000 @@ -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): diff -r 9f464eff218a Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/library/contextlib.rst Mon Mar 04 14:21:45 2013 +0000 @@ -361,7 +361,7 @@ from contextlib import contextmanager, ExitStack - class ResourceManager(object): + class ResourceManager: def __init__(self, acquire_resource, release_resource, check_resource_ok=None): self.acquire_resource = acquire_resource diff -r 9f464eff218a Doc/library/functions.rst --- a/Doc/library/functions.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/library/functions.rst Mon Mar 04 14:21:45 2013 +0000 @@ -323,7 +323,7 @@ '__initializing__', '__loader__', '__name__', '__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into', 'unpack', 'unpack_from'] - >>> class Shape(object): + >>> class Shape: ... def __dir__(self): ... return ['area', 'perimeter', 'location'] >>> s = Shape() diff -r 9f464eff218a Doc/library/unittest.mock-examples.rst --- a/Doc/library/unittest.mock-examples.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/library/unittest.mock-examples.rst Mon Mar 04 14:21:45 2013 +0000 @@ -45,7 +45,7 @@ This example tests that calling `ProductionClass().method` results in a call to the `something` method: - >>> class ProductionClass(object): + >>> class ProductionClass: ... def method(self): ... self.something(1, 2, 3) ... def something(self, a, b, c): @@ -69,7 +69,7 @@ The simple `ProductionClass` below has a `closer` method. If it is called with an object then it calls `close` on it. - >>> class ProductionClass(object): + >>> class ProductionClass: ... def closer(self, something): ... something.close() ... @@ -398,7 +398,7 @@ Where you use `patch` to create a mock for you, you can get a reference to the mock using the "as" form of the with statement: - >>> class ProductionClass(object): + >>> class ProductionClass: ... def method(self): ... pass ... @@ -446,7 +446,7 @@ So, suppose we have some code that looks a little bit like this: - >>> class Something(object): + >>> class Something: ... def __init__(self): ... self.backend = BackendProvider() ... def method(self): @@ -554,7 +554,7 @@ Here's an example class with an "iter" method implemented as a generator: - >>> class Foo(object): + >>> class Foo: ... def iter(self): ... for i in [1, 2, 3]: ... yield i @@ -664,7 +664,7 @@ It will have `self` passed in as the first argument, which is exactly what I wanted: - >>> class Foo(object): + >>> class Foo: ... def foo(self): ... pass ... @@ -1183,7 +1183,7 @@ You can see in this example how a 'standard' call to `assert_called_with` isn't sufficient: - >>> class Foo(object): + >>> class Foo: ... def __init__(self, a, b): ... self.a, self.b = a, b ... @@ -1210,7 +1210,7 @@ And a matcher object that can use comparison functions like this for its equality operation would look something like this: - >>> class Matcher(object): + >>> class Matcher: ... def __init__(self, compare, some_obj): ... self.compare = compare ... self.some_obj = some_obj diff -r 9f464eff218a Doc/library/unittest.mock.rst --- a/Doc/library/unittest.mock.rst Wed Oct 31 12:03:48 2012 +0200 +++ b/Doc/library/unittest.mock.rst Mon Mar 04 14:21:45 2013 +0000 @@ -695,7 +695,7 @@ Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. - >>> class Foo(object): + >>> class Foo: ... @property ... def foo(self): ... return 'something' @@ -1031,7 +1031,7 @@ To configure return values on methods of *instances* on the patched class you must do this on the `return_value`. For example: - >>> class Class(object): + >>> class Class: ... def method(self): ... pass ... @@ -1204,7 +1204,7 @@ magic methods `__getitem__`, `__setitem__`, `__delitem__` and either `__iter__` or `__contains__`. - >>> class Container(object): + >>> class Container: ... def __init__(self): ... self.values = {} ... def __getitem__(self, name): @@ -1378,7 +1378,7 @@ >>> value = 3 >>> >>> @patch('__main__.value', 'not three') - ... class Thing(object): + ... class Thing: ... def foo_one(self): ... print value ... def foo_two(self): @@ -2138,7 +2138,7 @@ `autospec` can't know about any dynamically created attributes and restricts the api to visible attributes. - >>> class Something(object): + >>> class Something: ... def __init__(self): ... self.a = 33 ... @@ -2181,7 +2181,7 @@ .. code-block:: python - class Something(object): + class Something: a = 33 This brings up another issue. It is relatively common to provide a default @@ -2192,7 +2192,7 @@ `autospec` doesn't use a spec for members that are set to `None`. These will just be ordinary mocks (well - `MagicMocks`): - >>> class Something(object): + >>> class Something: ... member = None ... >>> mock = create_autospec(Something) @@ -2207,7 +2207,7 @@ the spec. Thankfully `patch` supports this - you can simply pass the alternative object as the `autospec` argument: - >>> class Something(object): + >>> class Something: ... def __init__(self): ... self.a = 33 ...