-
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
Make _create_transformer_with_kwargs a public method #5492
Make _create_transformer_with_kwargs a public method #5492
Conversation
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Show resolved
Hide resolved
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Show resolved
Hide resolved
circuit: 'cirq.AbstractCircuit', *, context: Optional['cirq.TransformerContext'] = None | ||
) -> 'cirq.AbstractCircuit': | ||
return func(circuit, context=context, **kwargs) # type: ignore | ||
return transformer(circuit, context=context, **kwargs) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the type ignore? I guess it's because cirq.TRANSFORMER
is a callable protocol whose __call__
signature does not allow for extra kwargs. Might we be able to remove the type ignore by extending the signature with explicit kwargs?
In any case, there should be a comment explaining the reason for the ignore and linking to a mypy issue if there is one open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's because cirq.TRANSFORMER is a callable protocol whose call signature does not allow for extra kwargs.
Yes, that's right.
Might we be able to remove the type ignore by extending the signature with explicit kwargs?
This is not possible because function arguments are contravariant, so adding **kwargs
to the signature of the protocol would mean that every transformer would need to support a **kwargs : Any
; which is bad.
In any case, there should be a comment explaining the reason for the ignore and linking to a mypy issue if there is one open.
Added a comment.
cirq-core/cirq/transformers/target_gatesets/compilation_target_gateset.py
Show resolved
Hide resolved
Automerge cancelled: A required status check is not present. Missing statuses: ['Pytest Windows (3.7)', 'Pytest Windows (3.8)', 'Pytest Windows (3.9)'] |
Fixes #5491