-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fall back to .py files if stub for library module is missing #638
Comments
I like the idea of not complaining about type errors in modules that are in the stdlib or 3rd party dependencies that were just installed, not written by the user running mypy. I'm not sure that |
I like this feature idea as it should make it a lot easier to get up and running with mypy. I would like to assist in the implementation, I'm quite new to mypy so I'm not sure if my assistance is more of a burden or a help. Could you give some hints as to how one would go about a concrete implementation? I assume that the change would be something like: use the "current" mypy paths (pwd and It might be useful to add a |
Yes, your suggestion sounds reasonable. We'd report errors for files under Here are some general pointers that may be helpful:
Also, we need to add a way of setting the ignore flag for a module in a test case. Detecting Something like the Let me know if you'd like more specific pointers, and don't hesitate to ask questions if you get stuck :-) |
It looks as though mypy already supports optionally using I was playing around with that flag and came across something which is related to one component of #186. The example I was working with used the copy.copy() function, when mypy uses the system copy.py file it produces the error The error is produced in a component of mypy.build which means that during the build process, if we try to import a module from within a module which is in the |
Yeah, import errors should also be ignored in modules that we don't type check. About #186: PEP 484 doesn't actually suggest looking at the existence of a
This falling to In the strict type checking mode, we'd require an annotation for |
Another idea is to automatically run stub generator on any modules in PYTHONPATH that don't have stubs. We'd cache the generated stub files somewhere such as a |
Less important now that we have |
I'm not even sure I agree with this, if I understand the proposal correctly. How do we even know PYTHONPATH is relevant for the program? It's already used to find and run mypy; the program might use a different Python version (e.g. 2.7). |
Yeah, using PYTHONPATH doesn't seem like the right way to approach this. But anyway, we could have another way of finding where the standard library lives for the target Python version/interpreter. However, it may be better to just use the stub generator to generate dynamically typed stubs for all standard library modules instead of trying to get mypy to process these modules. |
I am not sure if related, but I am seeing this error with the very common |
@boompig Can you be more specific what error you see? Preferably with a tiny example that we can repro. |
Python file: #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os.path
import logging
import json
from six.moves import input
from argparse import ArgumentParser
import subprocess
import time
import boto3
from botocore.exceptions import ClientError
import yaml Contents of virtualenv from
python version 3.5.1 on Mac OS X Output of
|
OK, that's just because there are no stubs in typeshed for those modules yet (boto3, botocore.exceptions, and yaml -- the reason the latter has a different error message is that it's a known third party module). Feel free to submit a PR to add some or all of them to the typeshed repo. In the meantime, do not attempt to point mypy to the site-packages directory. (See the note in the docs, at the end of this page.) Instead, use |
The note Guido mentioned above is lost to the ages, but here is its text:
via the Internet Archive |
Actually the note just got moved; it's now on this page: http://mypy.readthedocs.io/en/latest/stubs.html In any case I'm not sure that we should really do what's described at the top of this issue. For third party code we now have PEP 561 (and we're silencing errors there as of #5303). |
Can we just close this issue? I think PEP 561 solves this general area. |
Yeah, I don’t think we are going to implement the original idea. |
If a program imports a (standard) library module that has no stub, mypy should look at the module implementation, if available. I.e., mypy should follow PYTHONPATH by default.
We should ignore errors in Python std lib modules and just try to infer which variables, types, functions, methods, etc. are defined in the library so that we can do basic type checking (e.g., checking argument names and counts when calling module-level functions) and we can use classes defined in the module in annotations.
Prerequisites: Mypy should not crash or report a parse error for most Python 3.[234] standard library modules. There should a stub for most std lib C modules.
Open issues: What about errors in 3rd party library modules? Maybe we should silence them as well? We'd just infer as much as we can, but we probably shouldn't complain about them.
The text was updated successfully, but these errors were encountered: