divmod-dev team mailing list archive
-
divmod-dev team
-
Mailing list archive
-
Message #00131
[Bug 844592] Re: Recognize _("text") from gettext.install(...)
I'm not the expert on gettext, but it occurs to me there could be a subtle difference.
At least:
In [18]: __builtins__._ == gettext.gettext
Out[18]: False
In [19]: __builtins__._
Out[19]: <bound method GNUTranslations.gettext of <gettext.GNUTranslations instance at 0x1661d40>>
In [20]: gettext.gettext
Out[20]: <function gettext at 0x13df938>
I get the same translations from calling either function, and the
proposed workaround works for me, but it's not always the case:
>From gettext doc:
gettext.install(domain[, localedir[, unicode[, codeset[, names]]]])
Changed in version 2.4: Added the codeset parameter.
Changed in version 2.5: Added the names parameter.
Thus if someone uses extra parameters of install, result of _() and
gettext.gettext() are different:
In [34]: gettext.install(APP, DIR, unicode=True)
In [36]: __builtins__._("test")
Out[36]: u'test'
In [37]: gettext.gettext("test")
Out[37]: 'test'
Here difference is unicode vs str, that is _() includes unicode=True
passed in install and gettext.gettext doesn't. I suppose similar
differences could arise from codeset and names parameters to install.
--
You received this bug notification because you are a member of Divmod-
dev, which is the registrant for Pyflakes.
https://bugs.launchpad.net/bugs/844592
Title:
Recognize _("text") from gettext.install(...)
Status in Pyflakes:
Won't Fix
Bug description:
gettext module provides convenience function gettext.install() that
injects a callable _ [single underscore] into builtins, so that
internationalized code can be written like this:
print _("text")
pyflakes reports every _ as undefined symbol.
moreover since it is injected in builtins, all imported modules have
that symbol, thus the following works:
# main.py
import gettext
import somemod
gettext.install(...)
#somemod.py
print _("text")
I'm not sure what sort of heuristic could be used to recognize _() when pyflake checks somemod.py.
Perhaps a command line argument for extra builtins?
To manage notifications about this bug go to:
https://bugs.launchpad.net/pyflakes/+bug/844592/+subscriptions
References