@@ -145,7 +145,7 @@ print a message for each get or set. Overriding :meth:`__getattribute__` is
145145alternate approach that could do this for every attribute. However, this
146146descriptor is useful for monitoring just a few chosen attributes::
147147
148- class RevealAccess(object) :
148+ class RevealAccess:
149149 """A data descriptor that sets and returns values
150150 normally and prints a message logging their access.
151151 """
@@ -162,7 +162,7 @@ descriptor is useful for monitoring just a few chosen attributes::
162162 print('Updating', self.name)
163163 self.val = val
164164
165- >>> class MyClass(object) :
165+ >>> class MyClass:
166166 ... x = RevealAccess(10, 'var "x"')
167167 ... y = 5
168168 ...
@@ -194,7 +194,7 @@ triggers function calls upon access to an attribute. Its signature is::
194194
195195The documentation shows a typical use to define a managed attribute ``x ``::
196196
197- class C(object) :
197+ class C:
198198 def getx(self): return self.__x
199199 def setx(self, value): self.__x = value
200200 def delx(self): del self.__x
@@ -203,7 +203,7 @@ The documentation shows a typical use to define a managed attribute ``x``::
203203To see how :func: `property ` is implemented in terms of the descriptor protocol,
204204here is a pure Python equivalent::
205205
206- class Property(object) :
206+ class Property:
207207 "Emulate PyProperty_Type() in Objects/descrobject.c"
208208
209209 def __init__(self, fget=None, fset=None, fdel=None, doc=None):
@@ -250,7 +250,7 @@ to be recalculated on every access; however, the programmer does not want to
250250affect existing client code accessing the attribute directly. The solution is
251251to wrap access to the value attribute in a property data descriptor::
252252
253- class Cell(object) :
253+ class Cell:
254254 . . .
255255 def getvalue(self):
256256 "Recalculate the cell before returning value"
@@ -277,7 +277,7 @@ binding methods during attribute access. This means that all functions are
277277non-data descriptors which return bound methods when they are invoked from an
278278object. In pure Python, it works like this::
279279
280- class Function(object) :
280+ class Function:
281281 . . .
282282 def __get__(self, obj, objtype=None):
283283 "Simulate func_descr_get() in Objects/funcobject.c"
@@ -287,7 +287,7 @@ object. In pure Python, it works like this::
287287
288288Running the interpreter shows how the function descriptor works in practice::
289289
290- >>> class D(object) :
290+ >>> class D:
291291 ... def f(self, x):
292292 ... return x
293293 ...
@@ -367,7 +367,7 @@ It can be called either from an object or the class: ``s.erf(1.5) --> .9332`` o
367367Since staticmethods return the underlying function with no changes, the example
368368calls are unexciting::
369369
370- >>> class E(object) :
370+ >>> class E:
371371 ... def f(x):
372372 ... print(x)
373373 ... f = staticmethod(f)
@@ -380,7 +380,7 @@ calls are unexciting::
380380Using the non-data descriptor protocol, a pure Python version of
381381:func: `staticmethod ` would look like this::
382382
383- class StaticMethod(object) :
383+ class StaticMethod:
384384 "Emulate PyStaticMethod_Type() in Objects/funcobject.c"
385385
386386 def __init__(self, f):
@@ -393,7 +393,7 @@ Unlike static methods, class methods prepend the class reference to the
393393argument list before calling the function. This format is the same
394394for whether the caller is an object or a class::
395395
396- >>> class E(object) :
396+ >>> class E:
397397 ... def f(klass, x):
398398 ... return klass.__name__, x
399399 ... f = classmethod(f)
@@ -410,7 +410,7 @@ is to create alternate class constructors. In Python 2.3, the classmethod
410410:func: `dict.fromkeys ` creates a new dictionary from a list of keys. The pure
411411Python equivalent is::
412412
413- class Dict(object) :
413+ class Dict:
414414 . . .
415415 def fromkeys(klass, iterable, value=None):
416416 "Emulate dict_fromkeys() in Objects/dictobject.c"
@@ -428,7 +428,7 @@ Now a new dictionary of unique keys can be constructed like this::
428428Using the non-data descriptor protocol, a pure Python version of
429429:func: `classmethod ` would look like this::
430430
431- class ClassMethod(object) :
431+ class ClassMethod:
432432 "Emulate PyClassMethod_Type() in Objects/funcobject.c"
433433
434434 def __init__(self, f):
0 commit comments