← Back to DAGDA | Support | Source: https://github.com/pyinstaller/pyinstaller/pull/4440
Skip to content

Fix strip_paths_in_code() for Python 3.8 - #4440

Merged
bjones1 merged 2 commits into
pyinstaller:developfrom
vstinner:code_replace
Oct 3, 2019
Merged

bjones1 merged 2 commits into
pyinstaller:developfrom
vstinner:code_replace

Conversation

@vstinner

@vstinner vstinner commented Sep 20, 2019 •

Copy link
Copy Markdown
Contributor

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

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>
@lkollar

This comment has been minimized.

@vstinner

This comment has been minimized.

@vstinner

This comment has been minimized.

@lkollar

This comment has been minimized.

@vstinner

Copy link
Copy Markdown
Contributor Author

@lkollar: CI tests now pass. Is there anything else to do to merge this fix? It's needed to support Python 3.8: see issue #4311.

@lkollar

This comment has been minimized.

@vstinner

This comment has been minimized.

@lkollar

lkollar commented Sep 29, 2019

Copy link
Copy Markdown
Contributor

Pinging @htgoebel @bjones1

I can confirm that with the latest 3.8 CPython build and @vstinner's patch this works:

$ cat test.py
import sys
print(sys.version)
$ pyinstaller test.py
91 INFO: PyInstaller: 4.0.dev0+g82cf4a62.mod
91 INFO: Python: 3.9.0a0
99 INFO: Platform: macOS-10.14.6-x86_64-i386-64bit
<omitted for brevity>
$ ./test/dist/test/test
3.9.0a0 (heads/master:58498bc, Sep 29 2019, 19:01:55)
[Clang 10.0.1 (clang-1001.0.46.4)]

@bjones1

bjones1 commented Oct 3, 2019

Copy link
Copy Markdown
Contributor

@vstinner, thanks for your contributions. Would you create the file news\4440.bugfix.rst, which should briefly explain the changes you made. In particular, reference PEP 570, and if you can find any links/docs to co_posonlyargcount and/or co_kwonlyargcount, that would be helpful. The file's format is reST, so a typical link would be:

`PEP 570 <https://www.python.org/dev/peps/pep-0570/>`_

@bjones1 bjones1 self-assigned this Oct 3, 2019
@vstinner

This comment has been minimized.

@bjones1

This comment has been minimized.

@bjones1
bjones1 merged commit 1b8345a into pyinstaller:develop Oct 3, 2019
@vstinner
vstinner deleted the code_replace branch October 3, 2019 22:35
@vstinner

This comment has been minimized.

@vstinner

This comment has been minimized.

@bjones1

This comment has been minimized.

@vstinner

This comment has been minimized.

@bjones1

This comment has been minimized.

@vstinner

This comment has been minimized.

)

if hasattr(co, 'co_posonlyargcount'):
return co.replace(co_consts=consts)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I know is_py38 is not yet here. It should get into live on te python-3.8 branch.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@htgoebel

This comment has been minimized.

@htgoebel

htgoebel commented Nov 16, 2019 •

Copy link
Copy Markdown
Member

Sorry to say, but this was a poor pull-request: Not only the new code checks for co_posonlyargcount instead of replace (see #4440 (comment)), and the commit message does not comply to our conventions. Much more important:

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.

@vstinner

Copy link
Copy Markdown
Contributor Author

Thanks for the fix.

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.

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants