From 919738a9d71ec4b321bef45b4701a1f4110da60a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 4 Mar 2019 12:08:48 +1000 Subject: [PATCH] print warning when add-ons access _ without importing it --- aqt/__init__.py | 7 +++++-- aqt/profiles.py | 4 ---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index 2e4a23901..9ac92045a 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -137,8 +137,11 @@ def setupLang(pm, app, force=None): # gettext _gtrans = gettext.translation( 'anki', dir, languages=[lang], fallback=True) - builtins.__dict__['_'] = _gtrans.gettext - builtins.__dict__['ngettext'] = _gtrans.ngettext + def fn(*args): + print("accessing _ and ngettext without importing from anki.lang will break in the future") + print("".join(traceback.format_stack()[-2])) + builtins.__dict__['_'] = fn + builtins.__dict__['ngettext'] = fn anki.lang.setLang(lang, local=False) if lang in ("he","ar","fa"): app.setLayoutDirection(Qt.RightToLeft) diff --git a/aqt/profiles.py b/aqt/profiles.py index 6d70d252f..ae9b17b36 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -357,10 +357,6 @@ please see: # On first run, allow the user to choose the default language def _setDefaultLang(self): - # the dialog expects _ to be defined, but we're running before - # setupLang() has been called. so we create a dummy op for now - import builtins - builtins.__dict__['_'] = lambda x: x # create dialog class NoCloseDiag(QDialog): def reject(self):