Open sils opened 8 years ago
From @AbdealiJK on February 19, 2016 4:41
Another exception:
[DEBUG][15:10:00] The bear RadonBear raised an exception. If you are the writer of this bear, please make sure to catch all exceptions. If not and this error annoys you, you might want to get in contact with the writer of this bear.
Traceback information is provided below:
Traceback (most recent call last):
File "/home/lasse/prog/coala/coalib/bears/Bear.py", line 97, in execute
return list(self.run_bear_from_section(args, kwargs) or [])
File "/home/lasse/prog/coala/coalib/misc/../../bears/python/RadonBear.py", line 32, in run
for visitor in radon.complexity.cc_visit("".join(file)):
File "/usr/lib/python3.5/site-packages/radon/complexity.py", line 93, in cc_visit
return cc_visit_ast(code2ast(code), **kwargs)
File "/usr/lib/python3.5/site-packages/radon/visitors.py", line 33, in code2ast
return ast.parse(source)
File "/usr/lib/python3.5/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 115
print '[EXTTEST]', msg % args
^
SyntaxError: Missing parentheses in call to 'print'
@rubik hey, apparently radon throws some exceptions at us. I see one of them is a SyntaxError, which makes sense we can catch that, the other is pretty weird, is radon running some of our code?!
CC @Makman2 @AbdealiJK from coala for investigation
Thanks for pinging me, I'll investigate. Radon just performs static analysis and doesn't run any code. The error is this one: https://github.com/coala-analyzer/coala/blob/3165f3a890eeec346fcdb24bda463440951a6fe6/coalib/results/TextRange.py#L32
It appears that in some results the end position is less than the start position, which is weird indeed. Can I see the code that's triggering the error?
EDIT: Since Python 2 is being used it's also possible that end
is None
and in Python 2 the expression None < 42
evaluates to True
. However, end
shouldn't be None
nevertheless.
FWIW coala will never work on python 2 though the analyzed code may be written in python 2. Do we have to spawn a python2 interpreter for radon in those cases?
@sils1297 - I'm unable to reproduce this. What did you run the bear on to get this ?
When I run it on coala it doesn't give this error.
@AbdealiJK that's a good question I gave pretty moch not the info we need for reproducing it :P for the second thing some python 2 or syntactically wrong python code should do.
I think I ran it on flask master. Could you try that?
@sils1297 Yes, a SyntaxError is always caused by Python 2 code or wrong syntax altogether. Radon can run on both Python 2 and 3, so that's not a problem. However, if one wants to analyze Python 2 code, Radon must be run with Python 2. I'll see what happens on Flask master.
Just ran coala
on Flask master. I got no errors. I used this .coafile
:
[Default]
files=flask/**/*.py
[python]
bears=RadonBear
I did the same, not able to reproduce.
On Mon, Feb 29, 2016 at 4:47 PM, Michele Lacchia notifications@github.com wrote:
Just ran coala on Flask master. I got no errors. I used this .coafile:
[Default] files=flask/*/.py
[python] bears=RadonBear
— Reply to this email directly or view it on GitHub https://github.com/coala-analyzer/coala-bears/issues/19#issuecomment-190161399 .
I had
files = **/*.py
use_spaces = true
[complexity]
bears = RadonBear
from a fresh cloned repository, i.e. no built files yet. Am definitely getting those errors for that.
using those version of coala/bears:
radon (1.2.3)
running it on e7d548595e8f2f03fb58c827bef8abae2f84aa59
Ok, I got it. Sometimes the end position has None
in the column field. That causes the error, as can be seen from this example:
In [1]: from coalib.results.TextPosition import TextPosition
In [2]: start, end = TextPosition(107, 0), TextPosition(107, None)
In [3]: end < start
Out[3]: True
Since Radon cannot know the end column (it parses the AST), I suggest that when an end position has a None
value in the column field, this is automatically set to 0
.
@rubik thanks for looking into this! So essentially Radon gives us a source range with a defined start and an undefined end column while we require all sourceranges to be completely defined. Any idea on what would be the most meaningful source range in that case? Replace None
by min(start.column, 0)
or something?
Exactly. Radon does not provide an end column, so min(start.column, 0)
seems reasonable.
@rubik thanks, with that we can work. What is the reason this happens anyway?
That's because Radon parses the AST, and each object in the tree has a line/column position. However, that's referring to the start position, while it's not possible to know the end position in the source code, since different code expressions could produce the same AST. Just adding/removing spaces around operators modifies the end position, but the AST of that expression is always the same.
In theory, Radon could know the start line/column of the last AST object. But labelling that as the end position of the code would be wrong and misleading. That's why I've chosen not to add an end column altogether.
From @sils1297 on February 18, 2016 14:10
Copied from original issue: coala-analyzer/coala#1578