Open purva-thakre opened 7 months ago
It might be better to ignore scipy
related warnings/errors raised by mypy
.
https://github.com/scipy/scipy/issues/19502#issuecomment-1806386197
The same issue in scipy
also applies to toqito
. So, we will have to
toqito.same_module
or https://mypy.readthedocs.io/en/stable/stubs.html#stub-files
How scipy
ignores all issues related to [import-untyped]
modules in their package: https://github.com/scipy/scipy/blob/fcf7b652bc27e47d215557bda61c84d19adc3aae/mypy.ini
To work on either of the above options, need to first fix toqito/channel_metrics/fidelity_of_separability.py: error: Source file found twice under different module names: "channel_metrics.fidelity_of_separability" and "toqito.channel_metrics.fidelity_of_separability"
. The same error is applied to all toqito.some_module
. Might be related to how mypy
finds the import path.
https://mypy.readthedocs.io/en/stable/running_mypy.html#how-imports-are-found
Edit: Ignoring all module is installed, but missing library stubs or py.typed marker
, issues that need to be fixed are in the attached file mypy_errors.txt. It might be better to create a PR per module or per function.
@vprusso FYI I am un-assigning myself from this issue.
I believe trying to fix some of the errors in the txt
file might require a major refactor considering quite a few functions allow multiple types of inputs and same variable is re-assigned a different value/type based on these inputs.
For example, the following lines are flagged by mypy
due to the redefinition. We disabled pylint
warnings for the same.
state_props/sk_vec_norm.py:61: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[Any]]", variable has type "int | list[int]") [assignment]
state_props/sk_vec_norm.py:62: error: Value of type "int" is not indexable [index]
state_props/sk_vec_norm.py:64: error: Unsupported target for indexed assignment ("int") [index]
state_props/sk_vec_norm.py:64: error: Value of type "int" is not indexable [index]
What if we defined one private method per allowed option for an input? Then we could call these in the main function sk_vector_norm
.
Sounds good, that's completely reasonable. Thanks for the heads up, @purva-thakre !
Great!
To close this issue:
mypy
to github workflows: Fix Source file found twice under different module names
, ignore toqito's stub
issues similar to scipy
, comment out mypy
lines in the workflow after fixing the quickly fixable errors.mypy
back to the workflows after items 3 and 4 are fixed.mypy
errors. Fix each item with a new PR.mypy
was ignoring import errors related to toqito's modules. Figured out a nice workaround to understanding what type mypy expects.
In some .py
file, add from typing import reveal_type
as an import. Then use reveal_type
to print the type of the output. This makes sure we are using types consistent with what's expected by mypy.
Note: We will have to use --explicit-package-bases
when running mypy in some directory because it gets confused with two modules having similarly named files.
https://mypy.readthedocs.io/en/stable/command_line.html#import-discovery
Add a check for mypy in https://github.com/vprusso/toqito/blob/200f3dc7a2178174d4ad6846f84686bc89c4c0ce/.github/workflows/build-test-actions.yml#L26
Right now,
~/toqito$ mypy .
fails due to following:scipy
is not intypeshed
as suggested bymypy's
docs.https://mypy.readthedocs.io/en/stable/config_file.html#config-file https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-library-stubs-or-py-typed-marker https://mypy.readthedocs.io/en/stable/stubs.html#stub-files https://mypy.readthedocs.io/en/stable/error_code_list.html#error-codes-enabled-by-default https://stackoverflow.com/a/64122820 https://stackoverflow.com/a/73390971 https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file