STINNER Victor added the comment: scandir-3.patch: New implementation based on scandir-2.patch on Ben's github repository.
Main changes with scandir-2.patch: * new DirEntry.inode() method * os.scandir() doesn't support bytes on Windows anymore: it's deprecated since python 3.3 and using bytes gives unexpected results on Windows As discussed with Ben Hoyt, I added a inode() method to solve the use case described here: https://www.reddit.com/r/Python/comments/2synry/so_8_peps_are_currently_being_proposed_for_python/cnvnz1w I will update the PEP 471 to add the inode() method. Notes: * os.scandir() doesn't accept a file descriptor, as decided in the PEP 471. * It may be nice to modify Scandir.close() to close the handle/directory; Scandir is the iterator returned by os._scandir() * My patch doesn't modify os.walk(): it prefer to do that in a new issue * DirEntry methods have no docstring Changes with scandir-2.patch: * C code is added to posixmodule.c, not into a new _scandir.c file, to avoid code duplication (all Windows code to handle attributes) * C code is restricted to the minimum: it's now only a wrapper to opendir+readdir and FindFirstFileW/FindNextFileW * os._scandir() directly calls opendir(), it's no more delayed to the first call to next(), to report errors earlier. In practice, I don't think that anymore will notify :-p * don't allocate a buffer to store a HANDLE: use directly a HANDLE * C code: use #ifdef inside functions, not outside * On Windows, os._scandir() appends "*.*" instead of "*" to the path, to mimic os.listdir() * put information about cache and syscall directly in the doc of DirEntry methods * remove promise of performances from scandir doc: be more factual, explain when syscalls are required or not * expose DT_UNKOWN, DT_DIR, DT_REG, DT_LNK constants in the posix module; but I prefer to not document them: use directly scandir! * rewrite completly unit test: - reuse test.support - compare DirEntry attributes with the result of functions (ex: os.stat() or os.path.islink()) * add tests on removed directory, removed file and broken symbolic link * remove ":" from repr(DirEntry) result, it's now "<DirEntry 'xxx'>"; drop __str__ method (by default, __str__ calls __repr__) * use new OSError subclasses (FileNotFoundError) * DirEntry methods: use stat.S_ISxxx() methods instead of "st.st_mode & 0o170000 == S_IFxxx" ---------- Added file: http://bugs.python.org/file38108/scandir-3.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22524> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com