f821 reports __module__ as undefined

Bug #1648651 reported by John Reese
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
New
Undecided
Unassigned

Bug Description

pyflakes reports F821 for "undefined name '__module__'", which is part of a set of available builtins: https://docs.python.org/3/reference/datamodel.html

Code to reproduce: https://gist.github.com/jreese/f81d30c867ed2eaeb3bd25318da29686

Running `pyflakes foo.py` generates F821 for the above code, but this value should be not be considered undefined.

Revision history for this message
asmeurer (asmeurer) wrote :

Python docs are confusing here. They say

> Special attributes: __name__ is the class name; __module__ is the module name in which the class was defined; __dict__ is the dictionary containing the class’s namespace; __bases__ is a tuple (possibly empty or a singleton) containing the base classes, in the order of their occurrence in the base class list; __doc__ is the class’s documentation string, or None if undefined.

but __dict__ and __bases__ are undefined in the class body (pyflakes seems to be correct for all except for __module__).

Revision history for this message
John Reese (jreese) wrote :

How easy would this be to fix? Would it help if I submitted a patch? If so, can you point me to the relevant part of the codebase that I should take a look at?

Revision history for this message
Ian Cordasco (icordasc) wrote :

John, that's not apparent to me. Have you tried searching the code-base for __dict__ or __bases__ to see if there is special handling?

Given that pyflakes works on a compiled AST, I have to wonder if this is a bug in Python's AST that is preventing us from recognizing __module__. I think we have a similar problem with __class__

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.