Skip to content

Should shutil functions support bytes paths? #90883

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

Open
JelleZijlstra opened this issue Feb 12, 2022 · 1 comment
Open

Should shutil functions support bytes paths? #90883

JelleZijlstra opened this issue Feb 12, 2022 · 1 comment
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

BPO 46727
Nosy @serhiy-storchaka, @JelleZijlstra, @AlexWaygood

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-02-12.01:43:24.033>
labels = ['type-bug', 'library', '3.11']
title = 'Should shutil functions support bytes paths?'
updated_at = <Date 2022-02-12.01:43:24.033>
user = 'https://github.com/JelleZijlstra'

bugs.python.org fields:

activity = <Date 2022-02-12.01:43:24.033>
actor = 'JelleZijlstra'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-02-12.01:43:24.033>
creator = 'JelleZijlstra'
dependencies = []
files = []
hgrepos = []
issue_num = 46727
keywords = []
message_count = 1.0
messages = ['413113']
nosy_count = 3.0
nosy_names = ['serhiy.storchaka', 'JelleZijlstra', 'AlexWaygood']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue46727'
versions = ['Python 3.11']

@JelleZijlstra
Copy link
Member Author

JelleZijlstra commented Feb 12, 2022

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:

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.

@JelleZijlstra JelleZijlstra added 3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 12, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant