pyflakes icon indicating copy to clipboard operation
pyflakes copied to clipboard

undefined name '__path__'

Open kisielk opened this issue 14 years ago • 1 comments

__path__ is a built-in attribute of all Python modules in a package so should not be flagged as undefined by pyflakes.

See http://docs.python.org/tutorial/modules.html#packages-in-multiple-directories

For example, create a directory called foo/ with __init__.py:

print __path__

Then run the python interpreter:

Python 2.6.4 (r264:75706, Jan 27 2010, 12:22:48) 
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import foo
['foo']
>>> 

I'm not sure if pyflakes can be made intelligent enough to not flag this only when working inside a package module, but it probably should just not flag it at all.

kisielk avatar Jan 06 '11 22:01 kisielk

I cannot reproduce this anymore:

Script started, file is /tmp/m
$ mkdir module
$ echo 'print __path__' >> module/__init__.py
$ cp module/__init__.py module/other.py
$ python
Python 2.7.3 (default, Sep 17 2012, 21:25:11) 
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import module
['module']
>>> from module import other
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "module/other.py", line 1, in <module>
    print __path__
NameError: name '__path__' is not defined
>>> 
$ pyflakes module/__init__.py
$ pyflakes module/other.py
module/other.py:1: undefined name '__path__'
$
Script done, file is /tmp/m

Looks to me that pyflakes behaviour is correct here (tried 06e149a6e3973535d25473e1c83e46d038103149).

resolve as WORKSFORME?

saper avatar Jan 06 '13 15:01 saper