This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "pdb -m " sets __main__.__package__ incorrectly
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: jaraco, mariocj89, ncoghlan
Priority: normal Keywords: patch

Created on 2018-01-28 05:04 by ncoghlan, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5474 merged mariocj89, 2018-02-01 16:01
PR 5510 merged miss-islington, 2018-02-03 06:41
Messages (7)
msg310917 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-01-28 05:04
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)
msg310964 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2018-01-28 16:17
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]`?
msg311437 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2018-02-01 15:19
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
msg311439 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-02-01 15:25
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).
msg311446 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2018-02-01 16:22
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!
msg311539 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-02-03 06:40
New changeset 38bfa8418f5d39bcc7478b8f7aef4a632c26172e by Nick Coghlan (Mario Corchero) in branch 'master':
bpo-32691: Use mod_spec.parent when running modules with pdb (GH-5474)
https://github.com/python/cpython/commit/38bfa8418f5d39bcc7478b8f7aef4a632c26172e
msg311591 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2018-02-04 08:07
New changeset 1a0239e12e161609fdf68f13cedbabca9bf353f1 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)
https://github.com/python/cpython/commit/1a0239e12e161609fdf68f13cedbabca9bf353f1
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76872
2018-02-05 02:39:08ncoghlansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-02-04 08:07:18ncoghlansetmessages: + msg311591
2018-02-03 06:41:25miss-islingtonsetpull_requests: + pull_request5343
2018-02-03 06:40:16ncoghlansetmessages: + msg311539
2018-02-01 16:22:22mariocj89setmessages: + msg311446
2018-02-01 16:01:42mariocj89setkeywords: + patch
stage: test needed -> patch review
pull_requests: + pull_request5302
2018-02-01 15:25:20ncoghlansetmessages: + msg311439
2018-02-01 15:19:36mariocj89setmessages: + msg311437
2018-01-28 16:17:43jaracosetmessages: + msg310964
2018-01-28 05:04:51ncoghlancreate