-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
mypy
produces errors when run on its own
#8070
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
Comments
In general, it's a good idea to run mypy on its own to catch any errors that might not be caught by other tools or in other environments. However, it's also important to make sure that the mypy configuration used when running on its own is consistent with the configuration used in other environments, such as pre-commit. |
I'm not exactly sure how the pre-commit config differs from the mypy config, if they're indeed different. However, the vast majority of the mypy errors that I'm seeing are about |
@tianyizheng02 mypy is a static checking tool used to identify type errors in Python code before it is run. Sometimes, mypy may report errors even though the code is correct. This could be due to the way mypy works. First, mypy checks type annotations in Python code at runtime and tries to infer the types of variables. It may report errors when it encounters situations where it cannot infer the type of a variable, such as when a variable is not assigned a value. Second, error reports from mypy may differ due to version and configuration differences. Sometimes, errors may be due to mypy's configuration or compatibility issues with other tools. If mypy's error reports prevent your code from running, you can try the following solutions: Update mypy version: Some errors may be due to using an outdated version of mypy. Upgrading to the latest version may resolve the issues. |
Here are a few factors that could contribute to the differences you're observing: Configuration Differences: The mypy configuration used when run on its own might be different from the configuration used by pre-commit. Check if there are any configuration files (e.g., mypy.ini, .mypy.ini, setup.cfg) that pre-commit is using to configure mypy. Ensure that the configuration options and settings are consistent between both invocations. Environment Variables: mypy can be influenced by environment variables such as MYPYPATH, PYTHONPATH, etc. Make sure that the environment variables are set consistently when running mypy directly and when running it through pre-commit. File Paths and Context: The way mypy is invoked by pre-commit might affect how it resolves file paths, dependencies, and other contextual information. Ensure that the paths and context are identical or compatible between both invocations. Version Differences: Make sure that the version of mypy used by pre-commit matches the version you're running on its own. Differences in behavior between mypy versions could also explain the discrepancies. Plugin Dependencies: If you're using any plugins or additional type stubs with mypy, make sure that they're installed and configured correctly for both invocations. Command Line Flags: Double-check that the command line flags and options passed to mypy are the same in both cases. Even small differences in flags can lead to different behavior. |
Feature description
Apologies if I'm misunderstanding about how
mypy
is set up with this repo.mypy
currently produces a litany of errors when run on its own even though it passes when run as part ofpre-commit
:Is this expected behavior? Should we expect
mypy
, when run on its own, to agree withpre-commit
?The text was updated successfully, but these errors were encountered: