[docs] [issue26330] shutil.disk_usage() on Windows can't properly handle unicode

Eryk Sun report at bugs.python.org
Sun Jan 14 20:27:27 EST 2018


Eryk Sun <eryksun at gmail.com> added the comment:

This is the high-level shutil module, so why not try to use the resolved parent directory? For example:

    def disk_usage(path):
        try:
            total, free = nt._getdiskusage(path)
        except NotADirectoryError:
            path = os.path.dirname(nt._getfinalpathname(path))
            total, free = nt._getdiskusage(path)
        used = total - free
        return _ntuple_diskusage(total, used, free)

Also, as noted in msg260022, nt._getdiskusage was overlooked when implementing PEP 529. The same applies to nt._getfinalpathname and nt._getvolumepathname. nt._getfullpathname works with bytes because it takes an argument-clinic `path_t` instead of `unicode` or `Py_UNICODE`. I think the other 3 should be rewritten to use path_t, but it's out of scope for this issue.

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26330>
_______________________________________


More information about the docs mailing list