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

Fix @takes_callable_and_args TypeVar binding bug #72

Merged
merged 1 commit into from
Mar 28, 2023
Merged

Fix @takes_callable_and_args TypeVar binding bug #72

merged 1 commit into from
Mar 28, 2023

Conversation

gschaffner
Copy link
Member

@gschaffner gschaffner commented Feb 8, 2023

resolves #71.

the change in the plugin's behavior bisects to python/mypy#14095, which changes the signature generated by the plugin:

  • before:

    reveal_type(nursery.start_soon)
    # note: Revealed type is "Overload(
    #     ...,  # other overloads
    #     def [__T1] (async_fn: def [__T1] (__T1`17) -> typing.Awaitable[Any], __T1`17, *, name: builtins.object =),
    #     ...,  # other overloads
    # )"
  • after:

    reveal_type(nursery.start_soon)
    # note: Revealed type is "Overload(
    #     ...,  # other overloads
    #     def [__T1] (async_fn: def [__T1] (__T1`93) -> typing.Awaitable[Any], __T1`94, *, name: builtins.object =),
    #     ...,  # other overloads
    # )"

    that is, what used to be one __T1 binding is now two different ones!

cc @oremanj, as this is your code :)

if merged, a new release should probably be made as this is effecting people in the wild.

@gschaffner gschaffner requested a review from oremanj February 8, 2023 10:47
Comment on lines -466 to +470
variables=(
list(callable_ty.variables)
+ cast(List[TypeVarLikeType], type_var_types)
),
# Note that we do *not* append `type_var_types` to
# `callable_ty.variables`. Even though `*type_var_types` are in our new
# `callable_ty`'s argument types, they are *not* type variables that get
# bound when our new `callable_ty` gets called. They get bound when the
# `expanded_fn` that references our new `callable_ty` gets called.
Copy link
Member

@belm0 belm0 Feb 15, 2023

Choose a reason for hiding this comment

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

Will this fix, in turn, cause errors from older mypy?

@oremanj
Copy link
Member

oremanj commented Mar 28, 2023

I tested the new code against an old mypy (0.982) and it produced the same correct-looking reveal_type output. It also seems to type-check correctly. Going to land it and hope for the best.

@oremanj oremanj merged commit e10a716 into python-trio:master Mar 28, 2023
@gschaffner gschaffner deleted the fix-takes_callable_and_args-TypeVar-binding branch May 10, 2023 03:12
@gschaffner
Copy link
Member Author

sorry for the delay!

but yeah, this should be fine on older mypy versions. in particular ci.sh tested this on the oldest mypy version supported by trio-typing.

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.

@takes_callable_and_args plugin is broken on Mypy v1.0.0
3 participants