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

Make _create_transformer_with_kwargs a public method #5492

Merged
merged 7 commits into from
Jun 14, 2022

Conversation

tanujkhattar
Copy link
Collaborator

Fixes #5491

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 13, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 13, 2022
@CirqBot
Copy link
Collaborator

CirqBot commented Jun 13, 2022

Automerge cancelled: A required status check is not present.

Missing statuses: ['Pytest Windows (3.7)', 'Pytest Windows (3.8)', 'Pytest Windows (3.9)']

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jun 13, 2022
@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 13, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 13, 2022
@CirqBot CirqBot merged commit 6e0e164 into quantumlib:master Jun 14, 2022
@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 14, 2022
@CirqBot CirqBot removed the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 14, 2022
@tanujkhattar tanujkhattar deleted the transformer_with_kwargs branch June 14, 2022 00:07
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make _create_transformer_with_kwargs public to enable vendor modules to use it.
4 participants