On Wed, Jul 27, 2016 at 11:05 AM, Jack Wilsdon <jack.wils...@gmail.com> wrote:
> Hi,
>
> I'm looking for a way to import __version__ / __author__ into my __init__.py 
> without causing an F401 error.
>
> Defining __version__ normally works fine:
>
>> init.py
>
>     __version__ = '1.0.0'
>     __author__ = 'Jack Wilsdon <jack.wils...@gmail.com>
>
> But if I define them in an external file and import them, I get an F401 error:
>
>> __version__.py
>
>     __version__ = '1.0.0'
>     __author__ = 'Jack Wilsdon <jack.wils...@gmail.com>
>
>> init.py
>
>     from __version__ import __version__, __author__  # I get an F
>
>> flake8 __init__.py
>
>     __init__.py:1:1: F401 '__version.__author__' imported but unused
>     __init__.py:1:1: F401 '__version.__version__' imported but unused
>
> Is there anything I can do about this? I know I could add "# noqa: F401" to 
> the end of the import, but it just feels like a bit of a "hack" to me.
>
> I could also add __version__ and __author__ to __all__ in init.py, but then 
> they would be imported if anyone used "from my_module import *", which is 
> definitely not what I want.
>
> Is this a bug in flake8/pyflakes or just my understanding of how __version__ 
> and __author__ are exempt from F401 errors normally.

I wouldn't consider it a bug in either. There might be a case for
special-casing some dunder variables but it's not really a bug. I'm
not sure why you think __version__ and __author__ are exempt from F401
errors normally. F401 means they were imported without being used.

If you mean, why don't I see F401 when I define them in __init__.py to
start with, then that's because like all module globals, pyflakes does
not check to see if it's used later because module constants may not
need to be used.
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality

Reply via email to