-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add type annotations to method overrides in child classes #554
Comments
Current abstract methods that should be checked.
|
Fixed this for simulators in #3818. Used generics so that child classes can return more specific subtypes, and mypy will catch if they return something else. I think it's a good template for others. |
Discussed on Cirq Cynque: heuristics for this
|
Hi, I am interested to work on this. If this issue is still open then could you assign it to me? |
I was looking into this commit as reference for the code And there are parts that I don't really understand. - class DensityMatrixSimulator(simulator.SimulatesSamples, simulator.SimulatesIntermediateState):
+class DensityMatrixSimulator(
+ simulator.SimulatesSamples,
+ simulator.SimulatesIntermediateStateBase[
+ 'DensityMatrixStepResult', 'DensityMatrixTrialResult', 'DensityMatrixSimulatorState'
+ ],
+): Why was it required to change from simulator.SimulatesIntermediateState to the Base class? And how were the items in the square brackets decided on? This happens a lot in that commit. If someone could explain how this works that would be really helpful |
Ping @daxfohl |
That commit added generics to the simulation classes. We could have probably gotten by more simply just by updating the return type of e.g. DensityMatrixSimulator.simulate from Iterator[StepResult] to Iterator[DensityMatrixStepResult]. But by making the simulator itself generic allows for slightly more powerful ability to write generic functions that do things with these generic classes in a type safe manner. LMK if you have any detailed questions. |
Ah thanks. That does make sense to me. |
Do |
Those were renamed to |
Bumping for @vtomole. |
Mypy hasn't caught that the implementation doesn't match the abstract method signature because they aren't currently type annotated.
Because of this, all gate types that implement both
ParameterizableGate
andTextDiagrammableGate
currently have the wrong type signature fortext_diagram_exponent()
:text_diagram_exponent() -> Union[value.Symbol, float]
vs.text_diagram_exponent() -> float
.The text was updated successfully, but these errors were encountered: