Skip to content
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

gh-98393: os module reject bytes-like, only accept bytes #98394

Merged
merged 2 commits into from Oct 18, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Oct 18, 2022

The os module no longer accepts bytes-like paths, like bytearray and memoryview types: only the exact bytes type is accepted for bytes strings.

@vstinner
Copy link
Member Author

vstinner commented Oct 18, 2022

cc @serhiy-storchaka @methane

The os module and the PyUnicode_FSDecoder() function no longer accept
bytes-like paths, like bytearray and memoryview types: only the exact
bytes type is accepted for bytes strings.
@vstinner vstinner merged commit db03c80 into python:main Oct 18, 2022
15 checks passed
@vstinner vstinner deleted the remove_os_buffer branch Oct 18, 2022
@vstinner
Copy link
Member Author

vstinner commented Oct 18, 2022

Merged, thanks for the review @methane!

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

LGTM besides few tests nitpicks.

@@ -3860,18 +3860,18 @@ def test_oserror_filename(self):

for filenames, func, *func_args in funcs:
for name in filenames:
try:
if isinstance(name, (str, bytes)):
if not isinstance(name, (str, bytes)):
Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move these cases into separate test. It is not anymore about the filename attribute of OSError.

self.assertIs(type(entry.name), bytes)
self.assertIs(type(entry.path), bytes)
with self.assertRaises(TypeError):
list(os.scandir(path_bytes))
Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list() is redundant here.

@vstinner
Copy link
Member Author

vstinner commented Oct 20, 2022

LGTM besides few tests nitpicks.

Since this PR is already merged, I created #98487 to take your review in account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants