Skip to content
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

runpy calls open_code with Path object #83698

Closed
TomasRavinskas mannequin opened this issue Feb 1, 2020 · 10 comments
Closed

runpy calls open_code with Path object #83698

TomasRavinskas mannequin opened this issue Feb 1, 2020 · 10 comments
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@TomasRavinskas
Copy link
Mannequin

TomasRavinskas mannequin commented Feb 1, 2020

BPO 39517
Nosy @ncoghlan, @zooba, @miss-islington, @tirkarthi, @kmaork
PRs
  • bpo-39517: fix runpy.run_path() when using pathlike objects #18699
  • [3.8] bpo-39517: Allow runpy.run_path() to accept path-like objects (GH-18699) #18862
  • 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:

    assignee = None
    closed_at = <Date 2020-03-08.20:44:44.210>
    created_at = <Date 2020-02-01.17:02:12.915>
    labels = ['3.8', 'type-bug', 'library', '3.9']
    title = 'runpy calls open_code with Path object'
    updated_at = <Date 2020-03-08.22:29:20.525>
    user = 'https://bugs.python.org/TomasRavinskas'

    bugs.python.org fields:

    activity = <Date 2020-03-08.22:29:20.525>
    actor = 'kmaork'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-08.20:44:44.210>
    closer = 'steve.dower'
    components = ['Library (Lib)']
    creation = <Date 2020-02-01.17:02:12.915>
    creator = 'Tomas Ravinskas'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39517
    keywords = ['patch']
    message_count = 10.0
    messages = ['361176', '361181', '361182', '362293', '362524', '363680', '363683', '363684', '363685', '363688']
    nosy_count = 6.0
    nosy_names = ['ncoghlan', 'steve.dower', 'miss-islington', 'xtreak', 'kmaork', 'Tomas Ravinskas']
    pr_nums = ['18699', '18862']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39517'
    versions = ['Python 3.8', 'Python 3.9']

    @TomasRavinskas
    Copy link
    Mannequin Author

    TomasRavinskas mannequin commented Feb 1, 2020

    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.

    @TomasRavinskas TomasRavinskas mannequin added type-crash A hard crash of the interpreter, possibly with a core dump 3.8 only security fixes stdlib Python modules in the Lib dir labels Feb 1, 2020
    @tirkarthi
    Copy link
    Member

    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.

    @tirkarthi tirkarthi added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 1, 2020
    @TomasRavinskas
    Copy link
    Mannequin Author

    TomasRavinskas mannequin commented Feb 1, 2020

    Can't see anything about this in the docs, I just noticed that it breaks shiv after upgrade.

    @kmaork
    Copy link
    Mannequin

    kmaork mannequin commented Feb 19, 2020

    Not a direct solution, but I have offered that io.open_code should be changed to support pathlike objects: https://bugs.python.org/issue39691

    @zooba
    Copy link
    Member

    zooba commented Feb 23, 2020

    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().

    @zooba zooba added the 3.9 only security fixes label Feb 23, 2020
    @kmaork
    Copy link
    Mannequin

    kmaork mannequin commented Mar 8, 2020

    Hey there, the PR was approved a week ago, is there a reason it is not merged yet?

    @zooba
    Copy link
    Member

    zooba commented Mar 8, 2020

    New changeset 0911ea5 by Maor Kleinberger in branch 'master':
    bpo-39517: Allow runpy.run_path() to accept path-like objects (GH-18699)
    0911ea5

    @zooba
    Copy link
    Member

    zooba commented Mar 8, 2020

    Nope, just that I apparently forgot to merge (or forgot to come back after CI had finished).

    Thanks for the reminder!

    @zooba zooba closed this as completed Mar 8, 2020
    @miss-islington
    Copy link
    Contributor

    New changeset 0687bdf by Miss Islington (bot) in branch '3.8':
    bpo-39517: Allow runpy.run_path() to accept path-like objects (GH-18699)
    0687bdf

    @kmaork
    Copy link
    Mannequin

    kmaork mannequin commented Mar 8, 2020

    Great, thank you!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants