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

Further improvements to functools.partial handling #17425

Merged
merged 7 commits into from
Jul 1, 2024

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Jun 22, 2024

  • Fixes another crash case / type inference in that case
  • Fix a false positive when calling the partially applied function with kwargs
  • TypeTraverse / comment / daemon test follow up ilevkivskyi mentioned on the original PR

See also #17423

- Fixes another crash case / type inference in that case
- Fix a false positive when calling the partially applied function
- TypeTraverse / comment / daemon test follow up ilevkivskyi mentioned
  on the original PR
@hauntsaninja hauntsaninja requested a review from ilevkivskyi June 22, 2024 22:26

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Some nice improvements here, I added more ideas.

mypy/plugins/functools.py Outdated Show resolved Hide resolved
mypy/plugins/functools.py Show resolved Hide resolved
mypy/plugins/functools.py Show resolved Hide resolved
seen_args.add(a)
actual_args.append(a)
actual_arg_kinds.append(ctx.arg_kinds[i][j])
actual_arg_names.append(ctx.arg_names[i][j])
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this it seems to me a better strategy for the call site may be using get_attribute_hook() for __call__? Unfortunately this hook is not called in is_subtype() etc yet. But at least it will be possible to precisely type-check something like this in future

def foo(fn: Callable[[int, str], int]) -> None: ...
fn = partial(some_other_fn, 1, 2)
foo(fn)

test-data/unit/check-functools.test Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jul 1, 2024

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit d1d3c78 into python:master Jul 1, 2024
18 checks passed
hauntsaninja added a commit that referenced this pull request Jul 1, 2024
- Fixes another crash case / type inference in that case
- Fix a false positive when calling the partially applied function with
kwargs
- TypeTraverse / comment / daemon test follow up ilevkivskyi mentioned
on the original PR

See also #17423
@hauntsaninja hauntsaninja deleted the functool-partial-more branch July 2, 2024 00:18
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.

3 participants