This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Should shutil functions support bytes paths?
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, JelleZijlstra, serhiy.storchaka
Priority: normal Keywords:

Created on 2022-02-12 01:43 by JelleZijlstra, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg413113 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-12 01:43
The shutil documentation doesn't say anything about bytes paths, and the CPython unit tests don't test them. But some functions do work with bytes paths in practice, and on typeshed we've received some requests to add support for them in the type stubs.

Links:
- https://github.com/python/typeshed/pull/7165/files (shutil.unpack_archive works with bytes paths, but only sometimes)
- https://github.com/python/typeshed/pull/6868 (shutil.make_archive)
- https://github.com/python/typeshed/pull/6832 (shutil.move accepts bytes paths, except when moving into an existing directory)

My overall impression is that bytes paths sometimes work by accident because they happen to not hit any code paths where we do os.path.join or string concatenation, but relying on them is risky because minor changes in the call site or in the file system can cause the call to break.

Here's three possible proposals:

(1) We document in the shutil docs that only str paths are officially supported. Bytes paths may sometimes work, but do it at your own risk.

(2) We add this documentation, but also make code changes to deprecate or even remove any support for bytes paths.

(3) We decide that bytes paths are officially supported, and we add tests for them and fix any cases where they don't work.

My preference is for (1). (2) feels like gratuitously breaking backward compatibility, and (3) is more work and there is little indication that bytes path support is a desired feature.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90883
2022-02-12 01:43:24JelleZijlstracreate