GithubHelp home page GithubHelp logo

Comments (7)

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by exarkun (@exarkun?) on Launchpad:


Instead of using the injected builtins feature of gettext, import the name. Then both pyflakes and human readers of the code will know what's going on.

from gettext import gettext as _

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by dimaqq (@dimaqq?) on Launchpad:


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.

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by exarkun (@exarkun?) on Launchpad:


The difference isn't really relevant to Pyflakes. The example I gave was meant to be a trivial example of how you can apply the solution. If you want a different gettext function to be bound to _, you can have a different gettext function bound to _. If you want unicode, use gettext.ugettext. If you want a particular domain, use the gettext.translation function to get an instance of something for the appropriate domain and then use that object's gettext method. etc.

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by kovid on Launchpad:


There are plenty of situations where large projects may decide to define project wide builtins, in order to save having to explicitly import a frequently used function in every single module. Please consider adding support for a user specified list of builtin names to ignore, either via a command line argument or an environment variable.

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by kovid on Launchpad:


And for completeness, here's a wrapper script that uses the env var PYFLAKES_BUILTINS

#!/usr/bin/env python
import os, builtin

names = os.environ.get('PYFLAKES_BUILTINS', '')
names = [x.strip() for x in names.split(',')]
for x in names:
if not hasattr(builtin, x):
setattr(builtin, x, True)

del names, os, builtin

from pyflakes.scripts.pyflakes import main
main()

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by florent.x (@florentx?) on Launchpad:


The version 0.6.1 added a parameter to the Checker constructor.
See issue 1107587: http://launchpad.net/bugs/1107587

An environment variable might be sensible for the command line usage.

from pyflakes.

pyflakes-bot avatar pyflakes-bot commented on August 28, 2024

Original comment by florent.x (@florentx?) on Launchpad:


Added environment variable PYFLAKES_BUILTINS as suggested. See NEWS.txt

from pyflakes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.