Skip to content

Commit 7dab8c9

Browse files
committed
Use deque to consume generator
1 parent 94beaaa commit 7dab8c9

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/pathlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import posixpath
1313
import sys
14+
from collections import deque
1415
from errno import *
1516
from glob import _StringGlobber, _no_recurse_symlinks
1617
from itertools import chain
@@ -1092,8 +1093,7 @@ def copy(self, target, **kwargs):
10921093
if not hasattr(target, 'with_segments'):
10931094
target = self.with_segments(target)
10941095
ensure_distinct_paths(self, target)
1095-
for _dst, _src in target._iter_copy_from(self, **kwargs):
1096-
pass
1096+
deque(target._iter_copy_from(self, **kwargs), maxlen=0)
10971097
return target.joinpath() # Empty join to ensure fresh metadata.
10981098

10991099
def copy_into(self, target_dir, **kwargs):

Lib/pathlib/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
from abc import ABC, abstractmethod
14+
from collections import deque
1415
from glob import _PathGlobber
1516
from io import text_encoding
1617
from pathlib._os import magic_open, ensure_distinct_paths, ensure_different_files, copyfileobj
@@ -337,8 +338,7 @@ def copy(self, target, **kwargs):
337338
Recursively copy this file or directory tree to the given destination.
338339
"""
339340
ensure_distinct_paths(self, target)
340-
for _dst, _src in target._iter_copy_from(self, **kwargs):
341-
pass
341+
deque(target._iter_copy_from(self, **kwargs), maxlen=0)
342342
return target.joinpath() # Empty join to ensure fresh metadata.
343343

344344
def copy_into(self, target_dir, **kwargs):

0 commit comments

Comments
 (0)