Skip to content
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

Fix mypy errors (providers) #8265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix mypy errors (providers) #8265

wants to merge 1 commit into from

Conversation

Randl
Copy link
Contributor

@Randl Randl commented Jun 29, 2022

Summary

Following discussion, I'm splitting #8187 by module.

Details and comments

The are ~40 errors left:

All error list

qiskit/providers/basicaer/basicaertools.py:65: error: Argument 1 to "Gate" has incompatible type "*List[float]"; expected "str"  [arg-type]
qiskit/providers/basicaer/basicaertools.py:65: error: Argument 1 to "Gate" has incompatible type "*List[float]"; expected "int"  [arg-type]
qiskit/providers/basicaer/basicaertools.py:65: error: Argument 1 to "Gate" has incompatible type "*List[float]"; expected "List[Any]"  [arg-type]
qiskit/providers/basicaer/basicaertools.py:65: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
qiskit/providers/basicaer/basicaertools.py:65: note: Consider using "Sequence" instead, which is covariant
qiskit/providers/basicaer/basicaertools.py:65: error: Argument 1 to "Gate" has incompatible type "*List[float]"; expected "Optional[str]"  [arg-type]
qiskit/providers/fake_provider/utils/backend_converter.py:86: error: Argument 1 to "InstructionProperties" has incompatible type "**Dict[str, Union[float, ParameterExpression]]"; expected "Optional[float]"  [arg-type]
qiskit/providers/fake_provider/utils/backend_converter.py:92: error: Invalid index type "str" for "str"; expected type "Union[SupportsIndex, slice]"  [index]
qiskit/providers/fake_provider/utils/backend_converter.py:93: error: Key expression in dictionary comprehension has incompatible type "Tuple[str, ...]"; expected type "str"  [misc]
qiskit/providers/fake_provider/utils/backend_converter.py:93: error: Invalid index type "str" for "str"; expected type "Union[SupportsIndex, slice]"  [index]
qiskit/providers/fake_provider/utils/backend_converter.py:97: error: Invalid index type "str" for "str"; expected type "Union[SupportsIndex, slice]"  [index]
qiskit/providers/fake_provider/utils/configurable_backend.py:104: error: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
qiskit/providers/fake_provider/utils/configurable_backend.py:159: error: Argument 1 to "zip" has incompatible type "Union[float, List[float]]"; expected "Iterable[float]"  [arg-type]
qiskit/providers/fake_provider/utils/configurable_backend.py:159: error: Argument 2 to "zip" has incompatible type "Union[float, List[float]]"; expected "Iterable[float]"  [arg-type]
qiskit/providers/fake_provider/utils/configurable_backend.py:159: error: Argument 3 to "zip" has incompatible type "Union[float, List[float]]"; expected "Iterable[float]"  [arg-type]
qiskit/providers/fake_provider/utils/configurable_backend.py:159: error: Argument 4 to "zip" has incompatible type "Union[float, List[float]]"; expected "Iterable[float]"  [arg-type]
qiskit/providers/fake_provider/utils/configurable_backend.py:234: error: Item "float" of "Union[float, List[float]]" has no attribute "__iter__" (not iterable)  [union-attr]
qiskit/providers/fake_provider/utils/configurable_backend.py:240: error: Argument "backend_version" to "PulseBackendConfiguration" has incompatible type "int"; expected "str"  [arg-type]
qiskit/providers/fake_provider/utils/configurable_backend.py:250: error: Argument "gates" to "PulseBackendConfiguration" has incompatible type "List[<nothing>]"; expected "GateConfig"  [arg-type]
qiskit/providers/models/backendconfiguration.py:622: error: Unsupported operand types for * ("Number" and "float")  [operator]
qiskit/providers/models/backendconfiguration.py:950: error: Invalid index type "Union[int, ParameterExpression]" for "List[List[UchannelLO]]"; expected type "SupportsIndex"  [index]
qiskit/providers/models/backendconfiguration.py:986: error: Incompatible return value type (got "Tuple[Dict[Tuple[Any, ...], List[Channel]], Dict[Channel, List[Any]], Dict[Tuple[Any, ...], List[Channel]]]", expected "Dict[Any, Any]")  [return-value]
qiskit/providers/models/backendproperties.py:219: error: Incompatible types in assignment (expression has type "Dict[Any, Tuple[float, Any]]", target has type "Dict[str, Tuple[Any, ...]]")  [assignment]
qiskit/providers/models/backendproperties.py:308: error: Incompatible types in assignment (expression has type "Dict[str, Tuple[Any, ...]]", variable has type "Dict[Tuple[Any, ...], Dict[str, Tuple[Any, ...]]]")  [assignment]
qiskit/providers/models/backendproperties.py:310: error: Incompatible types in assignment (expression has type "Dict[str, Tuple[Any, ...]]", variable has type "Dict[Tuple[Any, ...], Dict[str, Tuple[Any, ...]]]")  [assignment]
qiskit/providers/models/backendproperties.py:310: error: Invalid index type "str" for "Dict[Tuple[Any, ...], Dict[str, Tuple[Any, ...]]]"; expected type "Tuple[Any, ...]"  [index]
qiskit/providers/models/backendproperties.py:315: error: Incompatible return value type (got "Dict[Tuple[Any, ...], Dict[str, Tuple[Any, ...]]]", expected "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]")  [return-value]
qiskit/providers/models/backendproperties.py:347: error: Invalid tuple index type (actual type "str", expected type "Union[int, slice]")  [misc]
qiskit/providers/models/backendproperties.py:361: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:361: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:374: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:374: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:395: error: Incompatible types in assignment (expression has type "Tuple[float, Any]", variable has type "Dict[Any, Tuple[float, Any]]")  [assignment]
qiskit/providers/models/backendproperties.py:401: error: Incompatible return value type (got "Dict[Any, Tuple[float, Any]]", expected "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]")  [return-value]
qiskit/providers/models/backendproperties.py:413: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:413: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:425: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:425: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:437: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:437: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:449: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:449: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:461: error: Incompatible return value type (got "Union[Any, Tuple[Any, ...]]", expected "float")  [return-value]
qiskit/providers/models/backendproperties.py:461: error: Invalid index type "int" for "Union[Tuple[Any, datetime], Dict[str, Tuple[Any, ...]]]"; expected type "str"  [index]
qiskit/providers/models/backendproperties.py:475: error: Invalid tuple index type (actual type "str", expected type "Union[int, slice]")  [misc]
qiskit/providers/models/backendproperties.py:494: error: Incompatible return value type (got "Union[float, ParameterExpression]", expected "float")  [return-value]
qiskit/pulse/builder.py: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]

There are some ignores added to decorated property, since it's currently is not supported by mypy.

That's already a bit to much to specify all of the problems. I'll try to list those I identified.
There are some errors in qiskit/providers/basicaer/basicaertools.py due to the fact that Gate subclasses constructors are different from constructor of Gate.
There are also multiple errors in qiskit/providers/models/backendproperties.py due to the fact that qubit_property can return eithe dictionary or tuple depending on the runtime parameters.
There are some more that I'm unsure about fixes, help is appreciated.

@Randl Randl requested review from a team and jyu00 as code owners June 29, 2022 07:50
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@HuangJunye HuangJunye added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 29, 2022
@1ucian0 1ucian0 added the mypy Work related to support improving type hints in Qiskti code label Mar 30, 2023
@Randl Randl force-pushed the mypy-11 branch 2 times, most recently from 87f4bc6 to 2eeebe0 Compare May 23, 2023 14:59
@coveralls
Copy link

coveralls commented May 23, 2023

Pull Request Test Coverage Report for Build 5713433333

  • 38 of 42 (90.48%) changed or added relevant lines in 5 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 85.913%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/providers/fake_provider/utils/backend_converter.py 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 91.14%
Totals Coverage Status
Change from base Build 5684162640: 0.03%
Covered Lines: 73086
Relevant Lines: 85070

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 7370292470

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 87.532%

Totals Coverage Status
Change from base Build 7369683756: -0.02%
Covered Lines: 59258
Relevant Lines: 67699

💛 - Coveralls

@Randl
Copy link
Contributor Author

Randl commented Dec 31, 2023

ping @jyu00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo mypy Work related to support improving type hints in Qiskti code
Projects
Status: mypy
Development

Successfully merging this pull request may close these issues.

None yet

5 participants