mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-39916: Use os.scandir() as context manager in Path.glob(). (GH-18880)
This commit is contained in:
parent
e553f204bf
commit
704e2065f8
2 changed files with 6 additions and 2 deletions
|
@ -527,7 +527,8 @@ class _WildcardSelector(_Selector):
|
||||||
|
|
||||||
def _select_from(self, parent_path, is_dir, exists, scandir):
|
def _select_from(self, parent_path, is_dir, exists, scandir):
|
||||||
try:
|
try:
|
||||||
entries = list(scandir(parent_path))
|
with scandir(parent_path) as scandir_it:
|
||||||
|
entries = list(scandir_it)
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if self.dironly:
|
if self.dironly:
|
||||||
try:
|
try:
|
||||||
|
@ -557,7 +558,8 @@ class _RecursiveWildcardSelector(_Selector):
|
||||||
def _iterate_directories(self, parent_path, is_dir, scandir):
|
def _iterate_directories(self, parent_path, is_dir, scandir):
|
||||||
yield parent_path
|
yield parent_path
|
||||||
try:
|
try:
|
||||||
entries = list(scandir(parent_path))
|
with scandir(parent_path) as scandir_it:
|
||||||
|
entries = list(scandir_it)
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
entry_is_dir = False
|
entry_is_dir = False
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
More reliable use of ``os.scandir()`` in ``Path.glob()``. It no longer emits
|
||||||
|
a ResourceWarning when interrupted.
|
Loading…
Add table
Add a link
Reference in a new issue