logilab-astng #5571 Crash on module-level @staticmethod/@classmethod [resolved]
Maarten reported: When running pylint on this program: @staticmethod def f(): pass I get the following exception trace: Traceback (most recent call last): File "/usr/bin/pylint", line 4, in <module> lint.Run(sys.argv[1:]) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 901, in __init__ linter.check(args) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 492, in check self.check_astng_module(astng, checkers) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 602, in check_astng_module if implements(checker, IASTNGChecker)]) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 619, in astng_events self.astng_events(child, checkers, _reversed_checkers) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 619, in astng_events self.astng_events(child, checkers, _reversed_checkers) File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 616, in astng_events checker.visit(astng) File "/usr/lib/python2.5/site-packages/logilab/astng/utils.py", line 84, in visit method(node) File "/usr/lib/python2.5/site-packages/pylint/checkers/classes.py", line 206, in visit_function self._check_first_arg_for_type(node, klass.type == 'metaclass') AttributeError: Module instance has no attribute 'type' Although it is a bit unusual to have a static method at the module level, the Python interpreter accepts it. The same crash happens on @classmethod when used at the model level. I had a look at checkers/classes.py to see if fixing it would be easy, but it wasn't clear to me what the proper approach would be:
As a quick fix, I settled on the latter: klass_type = getattr(klass, 'type', None) # "klass" might not be a class And replace "klass.type" by "klass_type", once in checkers/classes.py and once in checkers/variables.py. | |
priority | important |
---|---|
type | bug |
done in | 0.17.4 |
load | 0.100 |
load left | 0.000 |
closed by | <not specified> |