pylint #6949 E0602 False Negative ("print __dict__ is not None") [resolved]
Nathaniel Manista: This is fairly trivial, but I couldn't find it currently tracked in the issue tracker. As the subject line indicates, the undefined-variable checker fails if the undefined variable is __dict__. I don't think anyone in their right mind would program that way, but that doesn't mean the check should fail. """This should not lint cleanly, but does.""" print __dict__ is not None | |
priority | important |
---|---|
type | bug |
done in | 0.16.0 |
load | 0.200 |
load left | 0.000 |
closed by | <not specified> |
Comments
-
2009/01/16 01:29, written by mkiilerich
-
2009/01/16 09:05, written by sthenault
-
2009/02/24 12:02, written by anon
-
2009/02/24 12:17, written by mkiilerich
add commentThe problem seems to be that the variable checkers visit_module initializes the scope/stack frame stack in self._to_consume with the .locals for the Module node, but .locals already contains __dict__. That causes visit_name to stay in the E0601 branch and it newer gets thrown to the E0602 branch as it does with all other names.
__name__, __file__ and __doc__ also exists in the module nodes .locals, but the difference is that these really do exist in the modules global scope at runtime - and also when referencing the module from outside. It seems like __dict__ is the only name where module.__dict__ is defined, but within the global scope of the module it is not defined. So perhaps it makes sense to make a special handling of __dict__ in visit_module and remove it from the copy of .locals?
yep, but we should take care of potential __dict__ assignment in the module. Also a fix to the builtin_lookup function of astng is needed to avoid E0601 false negative.
This is now fixed (test included) in pylint / astng repository.
Thanks!
not sure if it's the same bug, but it's a E0602 false negative:
for extension in extensions:
insert_every_four = ([[18, 19, 16, 17][i]] + j for i, j in enumerate(extension))
=> [E0602] Undefined variable 'extension'
No, I don't think it is related.
It might be due to limited support for comprehensions - like http://www.logilab.org/ticket/7925 .
BUT I can't reproduce your problem (haven't tried much, though). I suggest you file a separate issue and provide a full working example and information about your version of pylint.