Open tianyizheng02 opened 1 year ago
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. Although the errors could be because of different configuration,enviornment and timings
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. Although the errors could be because of different configuration,enviornment and timings
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 np.array
being used as a type. Mypy is definitely correct to mark these as errors because np.array
is a function (and np.ndarray
should be the correct type), so I don't know why these errors don't appear when mypy is run as part of pre-commit.
@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. Check type annotations: Correct usage of type annotations in your code is crucial as mypy works by checking type annotations. If you use complex or custom types in your code, ensure the definitions of these types are correct. Add more type annotations: Sometimes, mypy errors can be resolved by adding more type annotations. Mypy may generate errors when running alone because it is a static type checking tool that checks type annotations in Python code and reports type errors. If there are type errors in the code, mypy will generate error messages.
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
?