bpo-34537: Fix test_gdb:test_strings with LC_ALL=C#9483
Conversation
We cannot simply call locale.getpreferredencoding() here, as GDB might have been linked against a different version of Python with a different encoding and coercion policy with respect to PEP 538 and PEP 540. Thanks to Victor Stinner for a hint on how to fix this.
vstinner
left a comment
There was a problem hiding this comment.
LGTM, but I have a few minor requests.
| @@ -0,0 +1,2 @@ | |||
| Fix test_gdb:test_strings when LC_ALL=C and GDB was compiled with Python 3.6 | |||
There was a problem hiding this comment.
I suggest "test_gdb.test_strings()" or "test_strings() of test_gdb". You might use `` around function and file names.
| if err: | ||
| raise RuntimeError( | ||
| 'unable to determine the preferred encoding ' | ||
| 'of embedded Python in GDB.') |
There was a problem hiding this comment.
Would you mind to include err in the error message? You can use an f-string.
You might also raise the error if encoding is an empty string (if err or not encofing: ...)
| 'unable to determine the preferred encoding ' | ||
| 'of embedded Python in GDB.') | ||
|
|
||
| encoding = out.strip() |
There was a problem hiding this comment.
.rstrip() should be enough ;-)
| if not encoding: | ||
| raise RuntimeError( | ||
| f'unable to determine the preferred encoding ' | ||
| f'of embedded Python in GDB: the command returned no output') |
There was a problem hiding this comment.
Oh, I don't think that we need two code path, just reuse the first if.
There was a problem hiding this comment.
I mean, the first error message is fine if encoding is an empty string.
vstinner
left a comment
There was a problem hiding this comment.
LGTM. Thanks for update!
I tested manually the PR on Linux using LC_ALL=C: it works as expected.
We cannot simply call locale.getpreferredencoding() here, as GDB might have been linked against a different version of Python with a different encoding and coercion policy with respect to PEP 538 and PEP 540. Thanks to Victor Stinner for a hint on how to fix this. (cherry picked from commit 7279b51) Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
|
GH-9485 is a backport of this pull request to the 3.7 branch. |
We cannot simply call locale.getpreferredencoding() here, as GDB might have been linked against a different version of Python with a different encoding and coercion policy with respect to PEP 538 and PEP 540. Thanks to Victor Stinner for a hint on how to fix this. (cherry picked from commit 7279b51) Co-authored-by: Elvis Pranskevichus <elvis@magic.io>
We cannot simply call locale.getpreferredencoding() here,
as GDB might have been linked against a different version
of Python with a different encoding and coercion policy
with respect to PEP 538 and PEP 540.
Thanks to Victor Stinner for a hint on how to fix this.
https://bugs.python.org/issue34537