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
Fixing some byte-to-string conversion warnings #60049
Comments
This is related to bpo-15826. When run with the -b option, some glob.py and os.py functions give warnings due to byte-to-string conversions: amoura@amoura-laptop: The attached patch fixes this. There is a rather more mysterious phenomenon with exceptions (which is triggered by test_exceptions for ImportException, but it happens for any Exception class): >>> e = Exception(b'aaa')
[60596 refs]
>>> e.args[0]
b'aaa'
[60601 refs]
>>> str(e)
__main__:1: BytesWarning: str() on a bytes instance
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs]
>>> str(e)
"b'aaa'"
[60615 refs]
>>> e.args[0]
b'aaa'
[60615 refs] In other words, if a bytes argument is given to the exception, the first call to str triggers the warning, but further calls don't. Is this worth pursuing? |
Not repeating warnings from the same place is the default warning behavior. You can get all of them by passing -Wall. |
This should be "if not basename:" - if tail == curdir:
+ cdir = curdir
+ if isinstance(tail, bytes):
+ cdir = bytes(curdir, 'ASCII')
+ if tail == cdir: This will raise an error if curdir is a non-ascii str, so, unless the same error was already raised later in the code, this is backward incompatible. |
The first bug fixed in bpo-16696. |
On all supported platforms curdir is a ascii str (':' on Mac Classic, '.' on all other). The same idiom used in glob module. |
New changeset 9458a516f769 by Serhiy Storchaka in branch '3.2': New changeset f6cf2985348a by Serhiy Storchaka in branch '3.3': New changeset 51e60d9ee389 by Serhiy Storchaka in branch 'default': |
Fixed. Thank your for report and patch, Alessandro. |
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: