Closed wdawson closed 6 years ago
Yes, this is a good point. My work usually mandates that we use from __future__ import print_function
so I don't encounter this issue often, but you're right that it's kind of unfortunate to be able to get into a situation where no matter what you do, some linter will complain. I default to having both mypy2 and 3 enabled because, again, my work mandates this situation -- our code should run under python 2 and 3 whenever possible.
Let me think about what the least-disruptive way to handle this would be. For now is it sufficient to disable the version of mypy that isn't relevant to your situation?
It's probably good practice to try to be compatible with both versions, so maybe the defaults you have are sane. My workaround is below, but please be gentle on my elisp as it's not my strong suit 😉
(use-package flycheck-pycheckers)
(use-package flycheck
:ensure t
:init
(global-flycheck-mode)
:config
(add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup)
(setq flycheck-pycheckers-checkers '(pylint pep8 flake8 mypy3))
)
Right, that seems like the right approach. flycheck-pycheckers-checkers
is customizable for this reason (I use customize-variable
, not as familiar with the use-package
approach), so if the defaults are wrong for you, it should at least be easy to change :)
I suspect that any set of defaults I pick will be wrong for some significant subset of users, so I'm going to close this out. Thank you for your example config! I hope it can help someone else who may also experience this issue.
I have a potentially related question if you don't mind. I used this approach to make sure that I am only using mypy3 (because allowing both 2 and 3 messes with type-hints in 3.6), but what I am seeing is that when I launch emacs from inside my virtualenv, pylint runs inside the virtualenv (I know this because it marks module imports if they're not installed in the venv and doesn't mark them if they are) but mypy3 appears to run outside the venv no matter what because it always marks imported modules as unavailable even if they are installed in the venv.
How do I make sure that all of my checkers (i.e. pylint, flake8, mypy etc) are running from inside the venv?
@Abraxos Sorry, didn't see this for a while since it's on an issue marked as Closed. It sounds like flycheck-pycheckers is finding your virtualenv correctly -- can you verify that mypy is actually installed in that virtualenv, rather than in your global environment? If so, please open a new issue, and I can work on tracking it down!
By default, since you are including both mypy versions, the warnings and errors conflict. For example:
passes mypy2 but is invalid syntax in mypy3.
Conversely:
passes mypy3 but warns of unnecessary parens in mypy2.
Perhaps provide a python version configuration option, or be opinionated about which python version to support by default and pick that one.