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

Improve typing of inference functions #2166

Merged

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
🔨 Refactoring

Description

Follow-up to #2158.

Before, this was quite vague:

InferFn = Callable[..., Any]

@jacobtylerwalls jacobtylerwalls added the Maintenance Discussion or action around maintaining astroid or the dev workflow label May 6, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.0.0a3 milestone May 6, 2023
astroid/inference_tip.py Outdated Show resolved Hide resolved
astroid/inference_tip.py Outdated Show resolved Hide resolved
Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
@codecov
Copy link

codecov bot commented May 6, 2023

Codecov Report

Merging #2166 (b39202c) into main (0740a0d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2166   +/-   ##
=======================================
  Coverage   92.53%   92.54%           
=======================================
  Files          94       94           
  Lines       10804    10807    +3     
=======================================
+ Hits         9998    10001    +3     
  Misses        806      806           
Flag Coverage Δ
linux 92.30% <100.00%> (+<0.01%) ⬆️
pypy 87.48% <96.29%> (+<0.01%) ⬆️
windows 92.13% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
astroid/inference.py 94.58% <ø> (ø)
astroid/inference_tip.py 97.05% <100.00%> (-0.31%) ⬇️
astroid/nodes/node_ng.py 92.77% <100.00%> (+0.08%) ⬆️
astroid/transforms.py 100.00% <100.00%> (ø)
astroid/typing.py 100.00% <100.00%> (ø)

@DanielNoord
Copy link
Collaborator

@jacobtylerwalls think this is correct. Let me know what you think!

Copy link
Member Author

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

New mypy messages as of b3b6c53:

astroid/nodes/node_ng.py:147: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]
astroid/nodes/node_ng.py:149: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]

astroid/inference_tip.py Show resolved Hide resolved
astroid/inference_tip.py Outdated Show resolved Hide resolved
astroid/typing.py Outdated Show resolved Hide resolved
@DanielNoord
Copy link
Collaborator

New mypy messages as of b3b6c53:


astroid/nodes/node_ng.py:147: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]

astroid/nodes/node_ng.py:149: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]

I'll change it to be Node again.

@DanielNoord
Copy link
Collaborator

New mypy messages as of b3b6c53:


astroid/nodes/node_ng.py:147: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]

astroid/nodes/node_ng.py:149: error: Argument 1 to "__call__" of "InferFn" has incompatible type "NodeNG"; expected "Self"  [arg-type]

I'll change it to be Node again.

Scherm­afbeelding 2023-05-07 om 23 21 22

This seems to be a mypy bug. pyright correctly infers self to be Self and doesn't complain. Would you be okay with a type: ignore?

@jacobtylerwalls
Copy link
Member Author

Works for me. The blame will point back to this discussion in case mypy improves before we turn it on.

@DanielNoord
Copy link
Collaborator

Works for me. The blame will point back to this discussion in case mypy improves before we turn it on.

Implemented!

Copy link
Member Author

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

LGTM, I can't click Approve as the OP. Happy to squash merge once you ✅

node: _NodesT,
context: InferenceContext | None = None,
**kwargs: Any,
) -> Generator[InferenceResult, None, None]:
partial_cache_key = (func, node)
if partial_cache_key in _CURRENTLY_INFERRING:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated, but isn't this what the path wrapper does? Can we use that here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, but at glance, it looks like that one is sensitive to specific InferenceContexts. Here, we're not ready to unleash recursive inference with every slightly different context.

@jacobtylerwalls
Copy link
Member Author

Thanks for the review and for taking over!

@jacobtylerwalls jacobtylerwalls merged commit 900c546 into pylint-dev:main May 8, 2023
16 checks passed
@jacobtylerwalls jacobtylerwalls deleted the improve-inference-tip-typing branch May 8, 2023 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining astroid or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants