New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some syntax errors are not reported when linting from stdin #357
Comments
Seems that if I put in any arbitrary valid filename into Line 41 in 0b16364
|
Interesting. To be more accurate, it does not correctly raise the syntax error, but rather reads the text from a file with the given filename if it exists, which need not have anything to do with the actual code you passed into In any case, it seems to me that pyflakes should not assume that if For context, I discovered this because SublimeLinter pipes its buffer into pyflakes on stdin, and silently drops all reported issues that don't have a FILENAME:LINE:POSITION format. |
When raise loc = PyErr_ProgramTextObject(c->c_filename, LINENO(n));
if (!loc) {
Py_INCREF(Py_None);
loc = Py_None;
} PyObject *
PyErr_ProgramTextObject(PyObject *filename, int lineno)
{
FILE *fp;
if (filename == NULL || lineno <= 0)
return NULL;
fp = _Py_fopen_obj(filename, "r" PY_STDIOTEXTMODE);
if (fp == NULL) {
PyErr_Clear();
return NULL;
}
return err_programtext(fp, lineno);
} simple test here. ➜ echo 'for test' > \<stdin\>
➜ echo 'max(1 for i in range(10), key=lambda x: x+1)' | pyflakes
<stdin>:1:4: Generator expression must be parenthesized
for test
^ Maybe we should treat |
Yeah, seems like we might have to let the code know when |
in python3.9+ this does the right thing -- presumably due to a fix from cpython's side: $ echo 'max(1 for i in range(10), key=lambda x: x+1)' | python3.9 -m pyflakes
<stdin>:1:5: Generator expression must be parenthesized
max(1 for i in range(10), key=lambda x: x+1)
^ |
A quick test shows that python 3.6 through 3.8 are affected by this (tested with 3.6.15, 3.7.13, and 3.8.13 on Mac and asdf). |
personally I don't think it's worth it given it works fine in newer python |
In b73a3d1, there was an assumption that text is None only if there was an encoding error with the file. However this was the case for all pythons before 3.9 when reading code from stdin. This takes care to correctly report as much context as possible, so errors aren't silently dropped with the unhelpful "problem decoding source" message.
In b73a3d1, there was an assumption that text is None only if there was an encoding error with the file. However this was the case for all pythons before 3.9 when reading code from stdin. This takes care to correctly report as much context as possible, so errors aren't silently dropped with the unhelpful "problem decoding source" message.
In b73a3d1, there was an assumption that text is None only if there was an encoding error with the file. However this was the case for all pythons before 3.9 when reading code from stdin. This takes care to correctly report as much context as possible, so errors aren't silently dropped with the unhelpful "problem decoding source" message.
In b73a3d1, there was an assumption that text is None only if there was an encoding error with the file. However this was the case for all pythons before 3.9 when reading code from stdin. This takes care to correctly report as much context as possible, so errors aren't silently dropped with the unhelpful "problem decoding source" message.
Minimal reproduction (at least for Python 2.7.12 on Ubuntu 16.04 using pyflakes 2.0.0):
will not report the syntax error "Generator expression must be parenthesized if not sole argument" if piped into stdin as follows:
instead failing with a decoding error. However, this is not handled well by many integrations which parse pyflakes output for a lineno and offset.
It looks like there was an assumption in 2009 (from b73a3d1) that if
text is None
, then it's necessarily a decoding issue. I've yet to debug exactly why this specific class of syntax error does not include the text when reading from stdin.EDIT: just confirmed this affects python3 as well (using Python 3.7.0 on Alpine 3.8 using pyflakes 2.0.0)
The text was updated successfully, but these errors were encountered: