Skip to content

Fix minor issues in OSFS.scandir #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 27, 2021
Merged

Fix minor issues in OSFS.scandir #475

merged 4 commits into from
Mar 27, 2021

Conversation

althonos
Copy link
Member

@althonos althonos commented Mar 27, 2021

Type of changes

  • Bug fix

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @PyFilesystem/maintainers may be pedantic in the code review.

Description

Since Python 3.6, os.scandir returns an object that must be explicitly closed if the iteration stops before the iterator is exhausted. This PR does that, which should suppress ResourceWarning that were occasionally raised by an unclosed iterator in OSFS.scandir. I also changed the current OSFS.scandir code so that it only calls stat when necessary. Closes #311 .

I made it so tests.test_osfs.TestOSFS now treats warnings as errors, but it's still not 100% feasible to test this kind of warnings, because they are thrown on garbage collection, most of the time after our test case has finished running.

@althonos althonos added the bug label Mar 27, 2021
@coveralls
Copy link

coveralls commented Mar 27, 2021

Coverage Status

Coverage increased (+0.004%) to 95.367% when pulling 8aff8be on fix-scandir into b88f432 on master.

@althonos althonos added this to the v2.4.13 milestone Mar 27, 2021
@althonos althonos merged commit e6f0c8f into master Mar 27, 2021
@althonos althonos deleted the fix-scandir branch March 27, 2021 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ResourceWarning: unclosed scandir iterator
2 participants