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: Add Python hook function to replace NameError
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Rosuav, methane
Priority: normal Keywords: patch

Created on 2014-12-28 16:35 by Rosuav, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
nameerror_hook.patch Rosuav, 2014-12-28 16:35 review
Messages (3)
msg233149 - (view) Author: Chris Angelico (Rosuav) * Date: 2014-12-28 16:35
Creating an issue to keep track of a patch, but this probably wants to be discussed on python-ideas.

The attached patch allows a Python function to be put into sys.__getglobal__, which then works like __getattr__ but for global names. This allows interactive interpreters to auto-import, for instance:

def try_import(n):
    try: return __import__(n)
    except ImportError: raise NameError("Name %r is not defined"%n)

import sys
sys.__getglobal__ = try_import
msg238828 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-03-21 19:40
See the thread starting here https://mail.python.org/pipermail/python-ideas/2014-December/030521.html
msg339030 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2019-03-28 11:54
PEP 562 is implemented.
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67315
2019-03-28 11:54:57methanesetstatus: open -> closed

versions: + Python 3.7, - Python 3.5
nosy: + methane

messages: + msg339030
resolution: fixed
stage: resolved
2019-03-15 22:24:33BreamoreBoysetnosy: - BreamoreBoy
2015-03-21 19:40:22BreamoreBoysettype: enhancement

messages: + msg238828
nosy: + BreamoreBoy
2014-12-28 16:35:01Rosuavcreate