-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
os.getcwdb() doesn't implement PEP 528 (UTF-8) on Windows #81593
Comments
On Windows, os.getcwdb() is implemented using getcwd() on Windows. This function uses the ANSI code page, whereas PEP-529 "Change Windows filesystem encoding to UTF-8" is supposed to use UTF-8 for all bytes paths and filenames. Moreover, this function emits a DeprecationWarning, whereas PEP-529 was supposed to avoid the need to deprecated bytes paths and filenames on Windows. I guess that it was forgotten in the implementation of the PEP-529. Or was it a deliberate choice? Attached PR modify os.getcwdb() to use UTF-8. |
My PR 14396 modify os.getcwdb() to use UTF-8 and it removes the deprecation warning. |
See also bpo-32920. |
Definitely just an oversight. Thanks for fixing this! I think it can go to 3.8 as well. Thoughts? |
Oh, 3.8 is not released yet. Well, it's more or less a new feature, or a bugfix, depending on the point of view. I would not be comfortable to change the encoding in 3.8.1, but it should be fine to do the change in 3.8. |
I retargeted my PR 14396 to Python 3.8. |
Ok, it's merged into 3.8. Thanks for the review Steve. One less deprecation warning. |
This update breaks long-path support in Windows. It includes the following unnecessary check, which is using the wrong comparison operator:
PyMem_RawMalloc already checks this and returns NULL if size > (size_t)PY_SSIZE_T_MAX. This bug is causing a MemoryError with long paths: >>> p = 'C:/Temp/longpath' + ('/' + 'a' * 255) * 9
>>> os.chdir(p)
>>> len(os.getcwd())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError |
Oops. This is the risk of not testing a feature :-) My PR added very basic tests for getcwd() and getcwdb(). I wrote PR 14424 to not only fix the integer overflow check, but also to add a new unit tests for "long path". |
Ok, the regression should now be fixed and test_os now also tests os.getcwd() with a "long path" :-) Thank a lot Eryk Sun for your great advices on reviews! |
Oh. Now the test fails on macOS: https://buildbot.python.org/all/#/builders/145/builds/2021 Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.billenstein-sierra/build/Lib/test/test_os.py", line 115, in test_getcwd_long_path
self.assertEqual(cwd, expected)
AssertionError: '/private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpchlt91ay' != '/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpchlt91ay'
- /private/var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpchlt91ay
? + /var/folders/sy/9hwmqyx14s11577cvgzwf2v40000gt/T/tmpchlt91ay |
Fail on FreeBSD as well: https://buildbot.python.org/all/#/builders/168/builds/1222 ====================================================================== Traceback (most recent call last):
File "/usr/home/buildbot/python/3.x.koobs-freebsd-current/build/Lib/test/test_os.py", line 115, in test_getcwd_long_path
self.assertEqual(cwd, expected)
AssertionError: '/var/tmp/tmpq45z_od3' != '/tmp/tmpq45z_od3'
- /var/tmp/tmpq45z_od3
? + /tmp/tmpq45z_od3 |
This is fixed now, right? The buildbots seem happy at least. I'll close. |
Yeah, I forgot to close. I got some issues with backports, but the two commits are now merged into 3.8 as well. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: