Skip to content

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

2 participants