elarivie / linter-mypy Goto Github PK
View Code? Open in Web Editor NEWAtom Linter plugin to lint Python optional static type as defined in PEP 484
License: MIT License
Atom Linter plugin to lint Python optional static type as defined in PEP 484
License: MIT License
I recently started using pydantic and wanted the extra features brought by the mypy plugin.
Here is what my setup.cfg looks like
[mypy]
python_version = 3.8
files=**/*.py
plugins = pydantic.mypy
[pydantic-mypy]
init_typed = True
In the file foo.py
I have the following code:
from pydantic import BaseModel
class Foo(BaseModel):
bar: str
Foo(bar=1)
a: str = 1
When running mypy
in the command line I get the following errors (which are expected):
foo.py:6: error: Argument "bar" to "Foo" has incompatible type "int"; expected "str"
foo.py:7: error: Incompatible types in assignment (expression has type "int", variable has type "str")
However, in Atom, I only get the second error (which indicates the file in indeed watched by linter-mypy), but not the first one (provided by the pydantic-mypy plugin).
Do you have any ideas on how to debug this ?
Thank you !
I understand that linter-mypy
is able to read configs from mypy.ini
, but is it able to read from setup.cfg
?
I think the option to use a $PROJECT_NAME variable in the Executable Path option will be very useful to have a single configuration that can work with multiple virtual environments (for example those created with the virtualenvwrapper tool that are installed in the ~/.virtualenvs directory and that have by convention the same name of the project that uses it)
This would be similar to the Python Executable Paths of package autocomplete-python
/home/user/.virtualenvs/$PROJECT_NAME/bin/python
Thank you!
I was running a simple case:
a: int = "string"
mypy works well in the terminal environment. However, when I use linter-mypy, there will encounter an error as follows,
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 11, in main(None) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 91, in main res = type_check_only(sources, bin_dir, options, flush_errors, fscache) # noqa File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 148, in type_check_only fscache=fscache) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 185, in build flush_errors, fscache) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 285, in _build graph = dispatch(sources, manager) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2398, in dispatch process_graph(graph, manager) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2691, in process_graph process_stale_scc(graph, scc, manager) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/build.py", line 2823, in process_stale_scc manager.flush_errors(manager.errors.file_messages(graph[id].xpath), False) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mypy/main.py", line 81, in flush_errors f.write(msg + '\n') UnicodeEncodeError: 'ascii' codec can't encode characters in position 38-39: ordinal not in range(128)
I want to know what had happened, and how to fix it.
I have the linter package running on file saves, and everytime a red pop up tells me there was an internal error:
The line number however points to a valid lint regarding type checks, and if I fix it, and save the file again, I get again an internal error with the next first lint in that file as line number.
So this is weird for two reasons:
linter-mypy v2.5.2, Atom 1.23.3, Python 3.5.2. In a file OtherClassName.py:
from A.B.C.D.E.className import ClassName
"Cannot find module" warning is issued. Moving ClassName to parent folder, adjusting import to:
from A.B.C.D.className import ClassName
No problem finding module.
Adding $PROJECT_PATH/A/B/C/D/E or dot to MyPy path does not help.
In case that project folder contains dot e.g.
/path/project.name
then $PROJECT_NAME
contains only project
value instead of project.name
.
When I lint, the following notification is shown:
The typed_ast package is not installed. You can install it with python3 -m pip install typed-ast
.
I understand this may be an issue with mypy
itself (I've found a related issue), however running python -m mypy
doesn't have this error.
pip freeze
results (virtual environment):
appdirs==1.4.3
astroid==2.3.3
attrs==19.3.0
black==19.10b0
Click==7.0
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
mypy==0.750
mypy-extensions==0.4.3
pathspec==0.6.0
pkg-resources==0.0.0
pycodestyle==2.5.0
pydocstyle==4.0.1
pyflakes==2.1.1
pylama==7.7.1
pylama-pylint==3.1.1
pylint==2.4.4
regex==2019.11.1
six==1.13.0
snowballstemmer==2.0.0
toml==0.10.0
typed-ast==1.4.0
typing-extensions==3.7.4.1
wrapt==1.11.2
linter-mypy version 2.6.8 running on Ubuntu with Atom 1.41.0 x64.
It also took me a while to identify the error as being from this package.
Please don't run mypy inside project (using cwd). It's not recommended by mypy authors because it does not work correctly - python/mypy#2974
Pipenv creates virtual environments with a directory name that cannot be derived from $PROJECT_PATH or $PROJECT_NAME. Their way to run mypy, is pipenv run mypy ...
. or pipenv run python -m mypy
in the project root.
I can currently only set an executable path for python in the settings of linter-mypy. I think this issue would therefore be resolved if I could provide an executable path plus arguments (eg. $PROJECT_PATH/pipenv run python
).
I have recently gotten the following error after updating Atom.
Relevant information:
Argument to path.dirname
must be a string
Object.dirname (/Applications/Atom.app/Contents/Resources/app/src/electron-shims.js:9:10)
Object.lintPath (/Users/calgarymichael/.atom/packages/linter-mypy/lib/init.coffee:531:23)
Object.lint (/Users/calgarymichael/.atom/packages/linter-mypy/lib/init.coffee:846:28)
a.factory (/Users/calgarymichael/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-diagnostics/lib/services/LinterAdapter.js:252:42)
a._callFactory (/Users/calgarymichael/.atom/packages/atom-ide-ui/node_modules/rxjs/bundles/Rx.min.js:107:23)
a.tryDefer (/Users/calgarymichael/.atom/packages/atom-ide-ui/node_modules/rxjs/bundles/Rx.min.js:106:442)
Also, would it be possible to add a field for a list of paths to set as the $MYPYPATH in the settings?
This is similar to #20, but different.
After linting, there will be some errors/warnings from an imported file shown on the original file. I believe that turning off the follow imports setting should remove these messages, but it doesn't.
Linting the original file then results in duplicate warnings/errors.
Additionally, the messages are shown when linting another file that is not even in the same project (so there is definitely no import link).
Once the messages are shown, the only way to remove them is by reloading the editor/restarting Atom.
Hi, thanks for the great package.
I seem to have an unexpected behaviour : linter-mypy does not seem to find any installed package, even through I gave the right executable (referring to a conda environment having all the installed packages).
Do you have any ideas about where I could have messed up?
Thanks a lot,
Diviyan
Linter-mypy works great for my work, but I have a small issue.
The Python Executable Path
setting does not allow multiple paths.
I'd like to set "Use project-specific python if available, otherwise fallback to default python", but current linter-mypy does not seem to allow this.
I'm using type stubs in a project mine, and I put them under the $PROJECT_PATH/stubs/
directory. In my mypy.ini
, I set mypy_path
to stubs/
(it is a relative path on purpose). linter-mypy does not seem to be able to find my stubs, and behaves as if they are not there. I believe this is because linter-mypy runs mypy from the file system root, leading mypy to look for a /stubs/
directory which I don't have. I'm currently working around this issue by using my fork of this package that runs mypy in $PROJECT_PATH
.
According to my understanding of issue #4, linter-mypy runs mypy from the file system root to avoid work around a mypy limitation with finding the top-level package in a project. I guess this behavior shouldn't change for most users in order to avoid that mypy limitation. Maybe there should be an option to change the working directory for the mypy process?
First of all, thanks a lot for making this atom package! For sure it will help the Python community in the use of static typing!
I think a good addition to the linter would be to have the option to specify a per project mypy.ini file (using a $PROJECT placeholder variable). This way, users will have the control over wich options they would like to activate in a case by case basis.
For example, right now I would like to disable some Warnings regarding not found imports such as:
Cannot find module named 'aiohttp' at line 2 col 1
Cannot find module named 'aiopg' at line 3 col 1
This would be very easy if I could reference a mypy.ini file with the option:
--ignore-missing-imports
As suggested by the mypy executable itself:
aioxample@aioxample:~$ /opt/aioxample/env/bin/mypy /opt/aioxample/aioxample/polls/aiohttpdemo_polls/main.py
/opt/aioxample/aioxample/polls/aiohttpdemo_polls/main.py:3: error: Cannot find module named 'aiohttp'
/opt/aioxample/aioxample/polls/aiohttpdemo_polls/main.py:3: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
The option could be, for example:
$PROJECT/mypy.ini
For using a mypy.ini file located in the root of the repository. This path can be given to mypy executable through the --config-file option (http://mypy.readthedocs.io/en/latest/config_file.html).
Thanks a lot!
I use pyenv, and have mypy installed in an environment I use for python-related plugins: atom_env_3.6.7
. I set the path of mypy to reflect the correct python installation.
The error message says
The python package mypy does not seem to be installed. Install it with:
/my/path/to/home/.pyenv/versions/3.6.7/envs/atom_env_3.6.7/bin/python -m pip install mypy
But if I run
/my/path/to/home/.pyenv/versions/3.6.7/envs/atom_env_3.6.7/bin/python -m pip list
I get
Package Version
---------------------- -------
autopep8 1.4.3
...
mypy 0.700
...
And running the suggested install command does nothing because it's already installed
This started happening recently, so in the last one or two updates
I am playing around with MyPy with one of my Python packages, and so far linter-mypy
has been working great!
However, all my other repositories do not have typehints and in fact cause MyPy to crash due to python/mypy#4111. Is there some way to disable linter-mypy
for all repositories that do not have a mypy.ini
file in the repository root (or through another way of detecting if a repo is using mypy?)
Thanks!
Using a temp directory based on the filepath is much slower than allowing me to specify a path, especially if I use it on the CLI as well and then I can share a cache folder with other apps.
Hello,
I'm trying to use linter-mypy
with Python 3 project (python installed with pyenv
). When I run the linter, I get:
Even though I have mypy
installed, and the settings for linter-mypy
are correct, as far as I can tell.
$ /Users/npresta/.pyenv/shims/python -m pip install mypy
Requirement already satisfied: mypy in /Users/npresta/.pyenv/versions/3.6.2/lib/python3.6/site-packages
Requirement already satisfied: typed-ast<1.1.0,>=1.0.4 in /Users/npresta/.pyenv/versions/3.6.2/lib/python3.6/site-packages (from mypy)
Similarly, my settings are configured as such:
When I open up the console in Atom, I see:
> process.env['PATH']
> "/Users/npresta/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Any ideas? I'm using Atom Beta 1.20.0-beta4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.