@@ -1198,8 +1198,7 @@ Use the :func:`reversed` built-in function::
11981198 for x in reversed(sequence):
11991199 ... # do something with x ...
12001200
1201- This won't touch your original sequence, but build a new copy with reversed
1202- order to iterate over.
1201+ This returns a reverse iterator without modifying your original sequence.
12031202
12041203
12051204How do you remove duplicates from a list?
@@ -1642,8 +1641,8 @@ Use the built-in :func:`super` function::
16421641
16431642In the example, :func: `super ` will automatically determine the instance from
16441643which it was called (the ``self `` value), look up the :term: `method resolution
1645- order ` (MRO) with ``type(self).__mro__ ``, and return the next in line after
1646- ``Derived `` in the MRO: ``Base ``.
1644+ order ` (MRO) with ``type(self).__mro__ ``, and return a proxy that searches for
1645+ methods starting with the next class after ``Derived `` in the MRO: ``Base ``.
16471646
16481647
16491648How can I organize my code to make it easier to change the base class?
@@ -1686,7 +1685,7 @@ C)`` holds, unless overridden by ``c`` itself or by some class on the base-class
16861685search path from ``c.__class__ `` back to ``C ``.
16871686
16881687Caution: within a method of C, an assignment like ``self.count = 42 `` creates a
1689- new and unrelated instance named "count" in ``self ``'s own dict. Rebinding of a
1688+ new and unrelated attribute named "count" in ``self ``'s own dict. Rebinding of a
16901689class-static data name must always specify the class whether inside a method or
16911690not::
16921691
@@ -2055,30 +2054,6 @@ relevant instance attributes are mutable, the ``cached_property`` approach
20552054can't be made to work because it cannot detect changes to the
20562055attributes.
20572056
2058- To make the ``lru_cache `` approach work when the *station_id * is mutable,
2059- the class needs to define the :meth: `~object.__eq__ ` and :meth: `~object.__hash__ `
2060- methods so that the cache can detect relevant attribute updates::
2061-
2062- class Weather:
2063- "Example with a mutable station identifier"
2064-
2065- def __init__(self, station_id):
2066- self.station_id = station_id
2067-
2068- def change_station(self, station_id):
2069- self.station_id = station_id
2070-
2071- def __eq__(self, other):
2072- return self.station_id == other.station_id
2073-
2074- def __hash__(self):
2075- return hash(self.station_id)
2076-
2077- @lru_cache(maxsize=20)
2078- def historic_rainfall(self, date, units='cm'):
2079- 'Rainfall on a given date'
2080- # Depends on the station_id, date, and units.
2081-
20822057
20832058Modules
20842059=======
0 commit comments