diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-03-11 16:42:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-11 16:42:03 (GMT) |
commit | 704e2065f8b8021a4a6999470fb6ed3453f7679e (patch) | |
tree | f86ce0c47c65484b5d9d990bd1fd83bc7fc3573d /Lib/pathlib.py | |
parent | e553f204bf0e39b1d701a364bc71b286acb9433f (diff) | |
download | cpython-704e2065f8b8021a4a6999470fb6ed3453f7679e.zip cpython-704e2065f8b8021a4a6999470fb6ed3453f7679e.tar.gz cpython-704e2065f8b8021a4a6999470fb6ed3453f7679e.tar.bz2 |
bpo-39916: Use os.scandir() as context manager in Path.glob(). (GH-18880)
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r-- | Lib/pathlib.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 851aabd..2934620 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -527,7 +527,8 @@ class _WildcardSelector(_Selector): def _select_from(self, parent_path, is_dir, exists, scandir): try: - entries = list(scandir(parent_path)) + with scandir(parent_path) as scandir_it: + entries = list(scandir_it) for entry in entries: if self.dironly: try: @@ -557,7 +558,8 @@ class _RecursiveWildcardSelector(_Selector): def _iterate_directories(self, parent_path, is_dir, scandir): yield parent_path try: - entries = list(scandir(parent_path)) + with scandir(parent_path) as scandir_it: + entries = list(scandir_it) for entry in entries: entry_is_dir = False try: |