Repository navigation
Fix strip_paths_in_code() for Python 3.8 - #4440
Conversation
strip_paths_in_code() now uses CodeType.replace() if available to support the new CodeType construction (PEP 570: Positional-Only Parameters). Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I can confirm that with the latest 3.8 CPython build and @vstinner's patch this works: |
|
@vstinner, thanks for your contributions. Would you create the file |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| ) | ||
|
|
||
| if hasattr(co, 'co_posonlyargcount'): | ||
| return co.replace(co_consts=consts) |
There was a problem hiding this comment.
The changelog entry says: "use the new CodeType.replace() method if available." But the code does not test for .replace, but for co_posonlyargcount. While the later might be an indicator for the former, it is a different test.
Anyway: When using if is_py38 as a condition, we could spot this as a place where the othercode could be removed in some years when we drop support for Python 3.7.
There was a problem hiding this comment.
(I know is_py38 is not yet here. It should get into live on te python-3.8 branch.)
There was a problem hiding this comment.
This PR is already merged. You can replace hasattr(co, 'co_posonlyargcount') with hasattr(co, 'replace') if you want ;-) In practice, it's basically the same.
This comment has been minimized.
This comment has been minimized.
|
Sorry to say, but this was a poor pull-request: Not only the new code checks for It broke the relevant part of this method: replacing the filename. I just fixed it in f1813d5. Leasons learned: For new versions of Python, don't implement single, random fixes. Instead first set up a branch, activate CI testing, then start coding. |
|
Thanks for the fix.
It seems like an unit test is missing :-) At least, with the incorrect fix, I managed to build a binary :-) Without the fix, it failed with a Python exception. |
strip_paths_in_code() now uses CodeType.replace() if available to
support the new CodeType construction (PEP 570: Positional-Only
Parameters).
Co-Authored-By: Pablo Galindo Pablogsal@gmail.com