classification
Title: runpy calls open_code with Path object
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Tomas Ravinskas, kmaork, miss-islington, ncoghlan, steve.dower, xtreak
Priority: normal Keywords: patch

Created on 2020-02-01 17:02 by Tomas Ravinskas, last changed 2020-03-08 22:29 by kmaork. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18699 merged kmaork, 2020-02-29 11:19
PR 18862 merged miss-islington, 2020-03-08 20:43
Messages (10)
msg361176 - (view) Author: Tomas Ravinskas (Tomas Ravinskas) Date: 2020-02-01 17:02
runpy accepts Path like objects but open_code seems to only accept strings, so calling open_code with Path object throws TypeError.
I think runpy should call str() on all path passed to open_code.
The relevant line is 232 in runpy.py in function _get_code_from_file.
msg361181 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-02-01 17:50
Is there documentation in runpy where it's stated that path objects are accepted for the function? If not this seems to be an enhancement.
msg361182 - (view) Author: Tomas Ravinskas (Tomas Ravinskas) Date: 2020-02-01 17:58
Can't see anything about this in the docs, I just noticed that it breaks shiv after upgrade.
msg362293 - (view) Author: Maor Kleinberger (kmaork) * Date: 2020-02-19 23:04
Not a direct solution, but I have offered that io.open_code should be changed to support pathlike objects: https://bugs.python.org/issue39691
msg362524 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-02-23 16:56
open_code is correct according to PEP 578, so the fix here is for runpy to ensure the path is absolute and pass it through os.fsdecode() before calling io.open_code().
msg363680 - (view) Author: Maor Kleinberger (kmaork) * Date: 2020-03-08 20:20
Hey there, the PR was approved a week ago, is there a reason it is not merged yet?
msg363683 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-03-08 20:43
New changeset 0911ea5c172264eaefa3efe4a1788159c160920d by Maor Kleinberger in branch 'master':
bpo-39517: Allow runpy.run_path() to accept path-like objects (GH-18699)
https://github.com/python/cpython/commit/0911ea5c172264eaefa3efe4a1788159c160920d
msg363684 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-03-08 20:43
Nope, just that I apparently forgot to merge (or forgot to come back after CI had finished).

Thanks for the reminder!
msg363685 - (view) Author: miss-islington (miss-islington) Date: 2020-03-08 21:00
New changeset 0687bdf5def13ddca09e854113c0eac0772afea0 by Miss Islington (bot) in branch '3.8':
bpo-39517: Allow runpy.run_path() to accept path-like objects (GH-18699)
https://github.com/python/cpython/commit/0687bdf5def13ddca09e854113c0eac0772afea0
msg363688 - (view) Author: Maor Kleinberger (kmaork) * Date: 2020-03-08 22:29
Great, thank you!
History
Date User Action Args
2020-03-08 22:29:20kmaorksetmessages: + msg363688
2020-03-08 21:00:03miss-islingtonsetnosy: + miss-islington
messages: + msg363685
2020-03-08 20:44:44steve.dowersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-03-08 20:43:53steve.dowersetnosy: - miss-islington
messages: + msg363684
2020-03-08 20:43:30miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request18219
2020-03-08 20:43:25steve.dowersetmessages: + msg363683
2020-03-08 20:20:12kmaorksetmessages: + msg363680
2020-02-29 11:19:24kmaorksetkeywords: + patch
stage: patch review
pull_requests: + pull_request18060
2020-02-23 16:56:04steve.dowersetnosy: + steve.dower

messages: + msg362524
versions: + Python 3.9
2020-02-19 23:04:17kmaorksetnosy: + kmaork
messages: + msg362293
2020-02-01 17:58:26Tomas Ravinskassetmessages: + msg361182
2020-02-01 17:51:37xtreaksettype: crash -> behavior
2020-02-01 17:50:11xtreaksetnosy: + xtreak, ncoghlan
messages: + msg361181
2020-02-01 17:02:12Tomas Ravinskascreate