Skip to content

Further improvements to functools.partial handling - #17425

Merged
hauntsaninja merged 7 commits into
python:masterfrom
hauntsaninja:functool-partial-more
Jul 1, 2024
Merged

hauntsaninja merged 7 commits into
python:masterfrom
hauntsaninja:functool-partial-more

Conversation

@hauntsaninja

@hauntsaninja hauntsaninja commented Jun 22, 2024 •

Copy link
Copy Markdown
Collaborator
  • 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
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

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.

Comment thread mypy/plugins/functools.py Resolved
Comment thread mypy/plugins/functools.py Resolved
Comment thread mypy/plugins/functools.py Resolved
Comment thread mypy/plugins/functools.py
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
Copy Markdown
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)
Comment thread test-data/unit/check-functools.test Resolved
@github-actions

github-actions Bot commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

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
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

3 participants