Title: Add Python hook function to replace NameError
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Rosuav, inada.naoki
Priority: normal Keywords: patch

Created on 2014-12-28 16:35 by Rosuav, last changed 2019-03-28 11:54 by inada.naoki. This issue is now closed.

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
msg339030 - (view) Author: Inada Naoki (inada.naoki) * (Python committer) Date: 2019-03-28 11:54
PEP 562 is implemented.
Date User Action Args
2019-03-28 11:54:57inada.naokisetstatus: open -> closed

versions: + Python 3.7, - Python 3.5
nosy: + inada.naoki

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