As I’m relatively new to the python ecosystem some things, which may be obvious for many, continue to bother me a bit. The last problem I encounter, which block me for several days, was the following.
In my spare time, I’m developing carp, a python3 application to help me manage my different encFS containers. As I want to do clean stuff and learn good practice, I check my source code with flake8. And I setup internationalization too.
If I read the python documentation about the gettext module, I see that pushing the following lines at the top of my application is sufficient to have gettext working (1):
import gettext gettext.install("carp", PATH_TO_PO_FILES)
This, is responsible to install the
_ function in the global namespace. Problem is, if I do that, flake8 keeps complaining that
_ is undeclared. Then stupidly I redeclare it this way (2):
import gettext gettext.install("carp", PATH_TO_PO_FILES) _ = gettext.gettext
This is not working at all. Even if (1) was working as intended, as soon as I redeclare _ in (2), it stops working. Thus for now I come back to the explicit declaration (3) and it works as expected:
import gettext gettext.bindtextdomain("carp", PATH_TO_PO_FILES) gettext.textdomain("carp") _ = gettext.gettext
But still, I’m wondering why (2) does not work. Did I forget something? Surely, I misunderstood something, but I cannot point it out. Comments and explanations if you have some are very welcome.
(This post will be cross post to stackoverflow, I’ll update it with an answer from there if any good one comes.)