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: Few changes in sys.breakpointhook()
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, miss-islington, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2018-09-20 17:33 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9457 merged serhiy.storchaka, 2018-09-20 17:35
PR 11551 merged miss-islington, 2019-01-14 10:59
PR 11551 merged miss-islington, 2019-01-14 10:59
PR 11551 merged miss-islington, 2019-01-14 10:59
PR 11561 merged serhiy.storchaka, 2019-01-15 10:23
PR 11561 merged serhiy.storchaka, 2019-01-15 10:23
PR 11564 merged miss-islington, 2019-01-15 11:27
PR 11564 merged miss-islington, 2019-01-15 11:27
PR 11564 merged miss-islington, 2019-01-15 11:27
PR 11564 merged miss-islington, 2019-01-15 11:27
Messages (10)
msg325914 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-20 17:33
The proposed PR makes the following changes in sys.breakpointhook():

* Use _PyObject_GetBuiltin() for getting a builtin. This simplifies the code.

* The only effect of using the "from" list is when the imported name is a submodule. But it should be a callable. Callable module is very rare bird, I don't think we need to support such weird case. Removing the "from" list simplifies the code.

* Only ImportError and AttributeError raised from import are ignored. Other errors are exposed to the user as is. This is most likely a KeyboardInterrupt or MemoryError. They shouldn't be silenced.

sys.breakpointhook() was added in issue31353.
msg325932 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2018-09-20 21:03
Hi Serhiy.  I'm curious whether this is a pure clean up or if there are actual problems you're trying to fix.

* I'm okay with using _PyObject_GetBuiltin() but it does bother me in general to use too many non-public (and thus undocumented) APIs.  It makes understanding what's going on more difficult.  This is a general gripe of mine with Python's C API.

* Given that removing support for callable modules is technically a backward incompatible change, is it worth it?  If we had done it before 3.7 was released, it would have been fine, but now we can't guarantee it won't break someone's code.  I agree it's unlikely, but it is possible.

* Perhaps we should explicitly pass through KeyboardInterrupt and MemoryError rather than just ignoring ImportError and AttributeError.
msg325969 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-21 06:58
This is a pure clean up except the last item which fixes a minor problem. I had wrote this patch a while ago (perhaps before 3.7.0 was released), and now revive my old patches.

I think that the general rule is that exceptions shouldn't be ignored blindly, except in case when we have no choice (like in destructors). ImportError and AttributeError are expected exceptions raised in PyImport_ImportModuleLevelObject and PyObject_GetAttrString when PYTHONBREAKPOINT points to non-existing name, all other exceptions mean exceptional situation or programming error. Note that exceptions raised when call the hook are not ignored.
msg325970 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-21 06:59
I will drop cleanup changes if they don't look good to you.
msg333605 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-14 10:58
New changeset 6fe9c446f8302553952f63fc6d96be4dfa48ceba by Serhiy Storchaka in branch 'master':
bpo-34756: Silence only ImportError and AttributeError in sys.breakpointhook(). (GH-9457)
https://github.com/python/cpython/commit/6fe9c446f8302553952f63fc6d96be4dfa48ceba
msg333606 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-14 11:04
The part of the clean up was applied in PR 9519. And since _PyObject_GetBuiltin() was gone, the rest of the clean up no longer applicable. The only part that is left is to make unexpected exceptions no longer silenced.
msg333607 - (view) Author: miss-islington (miss-islington) Date: 2019-01-14 11:17
New changeset 6d0254bae4d739b487fcaa76705a2d309bce8e75 by Miss Islington (bot) in branch '3.7':
bpo-34756: Silence only ImportError and AttributeError in sys.breakpointhook(). (GH-9457)
https://github.com/python/cpython/commit/6d0254bae4d739b487fcaa76705a2d309bce8e75
msg333660 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-15 10:17
I reopen the issue. This change broke test_builtin: see bpo-35742.

I can reproduce the test failure on my Fedoea 29 using:

./python -m test -v test_builtin -m TestBreakpoint
msg333678 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-15 11:26
New changeset 3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a by Serhiy Storchaka in branch 'master':
bpo-35742: Fix test_envar_unimportable in test_builtin. (GH-11561)
https://github.com/python/cpython/commit/3607ef43c4a1a24d44f39ff54a77fc0af5bfa09a
msg333683 - (view) Author: miss-islington (miss-islington) Date: 2019-01-15 11:46
New changeset 97d6a56d9d169f35cf2a24d62bf15adfc42fc672 by Miss Islington (bot) in branch '3.7':
bpo-35742: Fix test_envar_unimportable in test_builtin. (GH-11561)
https://github.com/python/cpython/commit/97d6a56d9d169f35cf2a24d62bf15adfc42fc672
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 78937
2019-01-15 11:50:35serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-15 11:46:07miss-islingtonsetmessages: + msg333683
2019-01-15 11:27:28miss-islingtonsetpull_requests: + pull_request11219
2019-01-15 11:27:21miss-islingtonsetpull_requests: + pull_request11220
2019-01-15 11:27:14miss-islingtonsetpull_requests: + pull_request11218
2019-01-15 11:27:07miss-islingtonsetpull_requests: + pull_request11217
2019-01-15 11:26:57serhiy.storchakasetmessages: + msg333678
2019-01-15 10:23:27serhiy.storchakasetstage: resolved -> patch review
pull_requests: + pull_request11207
2019-01-15 10:23:18serhiy.storchakasetstage: resolved -> resolved
pull_requests: + pull_request11206
2019-01-15 10:17:06vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg333660

resolution: fixed -> (no value)
2019-01-14 11:34:46serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-14 11:17:10miss-islingtonsetnosy: + miss-islington
messages: + msg333607
2019-01-14 11:04:59serhiy.storchakasetmessages: + msg333606
2019-01-14 10:59:22miss-islingtonsetpull_requests: + pull_request11180
2019-01-14 10:59:16miss-islingtonsetpull_requests: + pull_request11179
2019-01-14 10:59:10miss-islingtonsetpull_requests: + pull_request11178
2019-01-14 10:58:41serhiy.storchakasetmessages: + msg333605
2018-09-21 06:59:54serhiy.storchakasetmessages: + msg325970
2018-09-21 06:58:52serhiy.storchakasetmessages: + msg325969
2018-09-20 21:03:51barrysetmessages: + msg325932
2018-09-20 17:35:24serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request8871
2018-09-20 17:33:39serhiy.storchakacreate