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

"pdb -m <module>" sets __main__.__package__ incorrectly #76872

Closed
ncoghlan opened this issue Jan 28, 2018 · 7 comments
Closed

"pdb -m <module>" sets __main__.__package__ incorrectly #76872

ncoghlan opened this issue Jan 28, 2018 · 7 comments
Labels
3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error

Comments

@ncoghlan
Copy link
Contributor

BPO 32691
Nosy @jaraco, @ncoghlan, @mariocj89
PRs
  • bpo-32691: Use mod_spec.parent when running modules with pdb #5474
  • [3.7] bpo-32691: Use mod_spec.parent when running modules with pdb (GH-5474) #5510
  • 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 2018-02-05.02:39:08.881>
    created_at = <Date 2018-01-28.05:04:51.391>
    labels = ['type-bug', '3.7']
    title = '"pdb -m <module>" sets __main__.__package__ incorrectly'
    updated_at = <Date 2018-02-05.02:39:08.880>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2018-02-05.02:39:08.880>
    actor = 'ncoghlan'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-02-05.02:39:08.881>
    closer = 'ncoghlan'
    components = []
    creation = <Date 2018-01-28.05:04:51.391>
    creator = 'ncoghlan'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32691
    keywords = ['patch']
    message_count = 7.0
    messages = ['310917', '310964', '311437', '311439', '311446', '311539', '311591']
    nosy_count = 3.0
    nosy_names = ['jaraco', 'ncoghlan', 'mariocj89']
    pr_nums = ['5474', '5510']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32691'
    versions = ['Python 3.7']

    @ncoghlan
    Copy link
    Contributor Author

    For regular modules, the initial implementation of bpo-32206 sets __package__ to "module_name" instead of "module_name.rpartition('.')[0]".

    This is not correct, and will cause problems for relative imports.

    (From https://bugs.python.org/issue32206#msg310882)

    @ncoghlan ncoghlan added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Jan 28, 2018
    @jaraco
    Copy link
    Member

    jaraco commented Jan 28, 2018

    In the backport, I found that mod_spec.parent seemed to be the right thing (in at least a few cases). Might that be preferable to module_name.rpartition('.')[0]?

    @mariocj89
    Copy link
    Mannequin

    mariocj89 mannequin commented Feb 1, 2018

    OK, just managed to reproduce it.

    This appears only when you run a python script as a module. Running a module with __main__ does not show the issue.

    Will get a patch ready

    @ncoghlan
    Copy link
    Contributor Author

    ncoghlan commented Feb 1, 2018

    I forget we had mod_spec.parent available to us these days, so yes, we should use that rather than recalculating the parent with str.rpartition.

    As Mario noted, we only want to change the behaviour when the executed module is a plain module or submodule, rather than being a package in its own right with a pkg.__main__ submodule (since the current behaviour is correct in the latter case).

    @mariocj89
    Copy link
    Mannequin

    mariocj89 mannequin commented Feb 1, 2018

    Sent a PR for the fix. I'll update PRs for trace. profile does not need it

    Thanks a lot for bringing it up Jason!

    @ncoghlan
    Copy link
    Contributor Author

    ncoghlan commented Feb 3, 2018

    New changeset 38bfa84 by Nick Coghlan (Mario Corchero) in branch 'master':
    bpo-32691: Use mod_spec.parent when running modules with pdb (GH-5474)
    38bfa84

    @ncoghlan
    Copy link
    Contributor Author

    ncoghlan commented Feb 4, 2018

    New changeset 1a0239e by Nick Coghlan (Miss Islington (bot)) in branch '3.7':
    [3.7] bpo-32691: Use mod_spec.parent when running modules with pdb (GH-5510)
    1a0239e

    @ncoghlan ncoghlan closed this as completed Feb 5, 2018
    @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.7 (EOL) end of life type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants