File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -110,8 +110,9 @@ def test_iter(self):
110110 # Test iterator
111111 # Don't need to count number of iterations since test would fail the
112112 # instant it returned anything beyond the first line from the
113- # comparison
114- for line in self .returned_obj .__iter__ ():
113+ # comparison.
114+ # Use the iterator in the usual implicit way to test for ticket #4608.
115+ for line in self .returned_obj :
115116 self .assertEqual (line , self .text )
116117
117118class ProxyTests (unittest .TestCase ):
Original file line number Diff line number Diff line change @@ -23,10 +23,14 @@ def __init__(self, fp):
2323 self .fileno = self .fp .fileno
2424 else :
2525 self .fileno = lambda : None
26- if hasattr (self .fp , "__iter__" ):
27- self .__iter__ = self .fp .__iter__
28- if hasattr (self .fp , "__next__" ):
29- self .__next__ = self .fp .__next__
26+
27+ def __iter__ (self ):
28+ # Assigning `__iter__` to the instance doesn't work as intended
29+ # because the iter builtin does something like `cls.__iter__(obj)`
30+ # and thus fails to find the _bound_ method `obj.__iter__`.
31+ # Returning just `self.fp` works for built-in file objects but
32+ # might not work for general file-like objects.
33+ return iter (self .fp )
3034
3135 def __repr__ (self ):
3236 return '<%s at %r whose fp = %r>' % (self .__class__ .__name__ ,
Original file line number Diff line number Diff line change @@ -309,6 +309,7 @@ Lele Gaifax
309309Santiago Gala
310310Yitzchak Gale
311311Quentin Gallet-Gilles
312+ Riccardo Attilio Galli
312313Raymund Galvin
313314Nitin Ganatra
314315Fred Gansevles
You can’t perform that action at this time.
0 commit comments