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

Clarify type hints for wrapped functions #25994

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ncoghlan
Copy link

Wrapped functions preserve the call signature of the
original function, but do NOT preserve other aspects
of the input type (such as additional attributes and
methods).

Avoids type checking failures from an upcoming
typeshed update which fixes this same discrepancy
in the signature of ContextDecorator.__call__.

Wrapped functions preserve the call signature of the
original function, but do NOT preserve other aspects
of the input type (such as additional attributes and
methods).

Avoids type checking failures from an upcoming
`typeshed` update which fixes this same discrepancy
in the signature of `ContextDecorator.__call__`.
Copy link

google-cla bot commented Jan 21, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ncoghlan
Copy link
Author

This PR is a follow up to this PR on typeshed that fixed the nominal signature of contextlib.ContextDecorator.__call__ to indicate that it preserves function call signatures, but not other aspects of the wrapped callables: python/typeshed#13416

One of the typeshed pre-merge checks picked up that jax had propagated a similarly incorrect wrapping function signature into its own type hints, which this PR aims to address.

@@ -3051,7 +3051,7 @@ def _cond(
index: TfVal, *operands: TfVal, branches: Sequence[core.ClosedJaxpr]
) -> Sequence[TfVal]:
# tf.cond needs lambdas with no arguments.
branches_tf = [
branches_tf: list[Callable[[], Any]] = [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative fix here would be to use two different local variable names, but the type declaration also statically enforces the expected outcome of the list comprehension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant