0

I might spot a false positive with emacs flycheck an python. This is happen when a I write in a file :

from sys import *
print('this is an error, like you 3:)', file = stderr)

Python run correctly but flycheck tell me that there is a syntax error. (I used standard error for the example but it's happen with any file descriptor)

This is not a real problem but it's a bit boring cause flycheck don't point out any next syntax error in the buffer.

EDIT : This is not a code error see screenshot error screenshot

EDIT 2 :

$ python --version
Python 3.4.2
Welgriv
  • 714
  • 9
  • 24
  • I don't have `flycheck` set up, but if I run `flake8` on that file, it complains about the `import *`; you should use `import sys; sys.stderr` or `from sys import stderr`. It also complains about the spaces around `=`. – jpkotta Nov 05 '18 at 20:50
  • If I am not mistaken, flake is only about coding style... What about : `f = open('a','w') print('this is an error, like you 3:)', file=f)` – Welgriv Nov 07 '18 at 09:26
  • https://www.flycheck.org/en/latest/languages.html#python – jpkotta Nov 08 '18 at 16:25
  • @jpkotta This link do not provide any solutions. – Welgriv Nov 12 '18 at 09:46

1 Answers1

0

Your code triggers the following warnings with the syntax checker python-flake8 (Version: 3.5.0) and no config file that alters the default behaviour. The problem is not with Flycheck but with your code:

 1   1 warning  F403   'from sys import *' used; unable to detect undefined names (python-flake8)
 2  45 warning  E251   unexpected spaces around keyword / parameter equals (python-flake8)
 2  47 warning  E251   unexpected spaces around keyword / parameter equals (python-flake8)
 2  48 warning  F405   'stderr' may be undefined, or defined from star imports: sys (python-flake8)

M-x flycheck-list-errors which is bound to C-c ! l by default will show you exactly this.

The following would not yield any errors:

from sys import stderr

print('this is an error, like you 3:)', file=stderr)
Simon Fromme
  • 3,104
  • 18
  • 30
  • sorry but no. I copy past your code and the error is still here, see screenshot in the edit of my first post – Welgriv Nov 12 '18 at 09:45
  • Maybe you haven't setup your syntax checker to use Python 3 instead of Python 2? – Simon Fromme Nov 12 '18 at 09:50
  • What Syntax checkers are enabled when you call `M-x flycheck-verify-setup` in your Python-buffer? – Simon Fromme Nov 12 '18 at 09:54
  • how do you set up the syntax checker to Python 3 ? I think my syntax checker is pycompile. `flycheck-verify-setup` return `Symbol's function definition is void: cl-struct-define` – Welgriv Nov 12 '18 at 10:17
  • Hm, the problem you are having with calling `flycheck-verify-setup` might be resolved by removing old elc compilations with `cd ~/.emacs.d/ && find . -name '*.elc' | xargs rm`. If your syntax checker is just pycompile than flycheck will presumably just call `python` on your file and report whatever errors that displays. If `python --version` shows `2.x` you could customize `flycheck-python-pycompile-executable` with `python3` or something. – Simon Fromme Nov 12 '18 at 10:31
  • I would probably install `flake8` or `pylint` though (e.g. `pip3 install flake8`). – Simon Fromme Nov 12 '18 at 10:35
  • I'm using python 3. Unfortunately I am not root so I can't properly install any package (need to be placed in my '/HOME' that is quite small). Are you sure that `.elc` are just used for compiling ? I have a lot of them in my `.emacs.d/`, I don't want to break everything ^^' – Welgriv Nov 13 '18 at 14:58
  • What does "I'm using python 3" mean? If `python --version` is `3.x`, pycompile is the syntax checker that flycheck is using and `flycheck-python-pycompile-executable` is also `python` then you shouldn't see the errors. `*.elc` files are just byte-compiled `*.el` files. If you still have `foo.el` you can delete `foo.elc` and emacs will re-compile. If unsure just make a backup! – Simon Fromme Nov 13 '18 at 16:29