mypy type check errors with default argument to cirq protocols. #4992
Labels
area/mypy
area/protocols
kind/bug-report
Something doesn't seem to work.
priority/p2
Next release should contain it
triage/accepted
A consensus emerged that this bug report, feature request, or other action should be worked on
Description of the issue
This came up while reviewing #4881 and offline discussions with @Zshan0.
A common pattern used throughout cirq protocols is to take a
default: TDefault
parameter which should be returned if the protocol does not succeed, or raise a type error if no explicit default has been provided. For example:Cirq/cirq-core/cirq/protocols/unitary_protocol.py
Lines 42 to 44 in 87d3632
Cirq/cirq-core/cirq/protocols/unitary_protocol.py
Lines 89 to 91 in 87d3632
However, this construct actually raises a mypy error and is a known issue -- python/mypy#8739
How to reproduce the issue
Here is a minimal failing example that follows a similar construct:
https://mypy-play.net/?mypy=latest&python=3.10&gist=f60ce6c21997d6559f0bf5bbe0881230
Summary
There are two different issues here that need to fixed:
./check/mypy
does not detect this error.default
parameter of protocols. (eg: by using the overload + optional signature for default).Cirq version
0.14dev
The text was updated successfully, but these errors were encountered: