Skip to content

Commit 5d06c74

Browse files
committed
Merge: #23700: fix/improve comment
2 parents a4d4dd3 + 75ed90a commit 5d06c74

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/tempfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,10 @@ def close(self):
427427
# iter() doesn't use __getattr__ to find the __iter__ method
428428
def __iter__(self):
429429
# Don't return iter(self.file), but yield from it to avoid closing
430-
# file as long as it's being used as iterator, see issue #23000.
431-
# XXX Also don't use "yield from"!
430+
# file as long as it's being used as iterator (see issue #23700). We
431+
# can't use 'yield from' here because iter(file) returns the file
432+
# object itself, which has a close method, and thus the file would get
433+
# closed when the generator is finalized, due to PEP380 semantics.
432434
for line in self.file:
433435
yield line
434436

0 commit comments

Comments
 (0)