-
-
Notifications
You must be signed in to change notification settings - Fork 306
Fix incorrect scope for functools partials #1097
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
Merged
Pierre-Sassoulas
merged 5 commits into
pylint-dev:main
from
Alphadelta14:partial-incorrect-scope
Aug 1, 2021
Merged
Fix incorrect scope for functools partials #1097
Pierre-Sassoulas
merged 5 commits into
pylint-dev:main
from
Alphadelta14:partial-incorrect-scope
Aug 1, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Alphadelta14
added a commit
to Alphadelta14/pylint
that referenced
this pull request
Jul 12, 2021
4 tasks
|
I tested in pylint and I got: On : def func_call():
"""Test we don't emit a FP for https://github.com/PyCQA/pylint/issues/2588"""
partial_func = partial(root_function, 1, 2, 3)
partial_func()
return root_function(1, 2, 3) # false positive too-many-function-args |
|
okay. I've figured out how to reproduce that test locally. Will make sure that is addressed! |
Alphadelta14
commented
Jul 12, 2021
Alphadelta14
commented
Jul 12, 2021
Pierre-Sassoulas
approved these changes
Jul 13, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's working in pylint now 👍
2 tasks
Pierre-Sassoulas
pushed a commit
to Alphadelta14/pylint
that referenced
this pull request
Apr 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Steps
Description
While working on pylint-dev/pylint#4357, I happened to notice an issue with partial functions where a given scope had both the original function and some remote partial usage returned by the same inference call.
I tracked the underlying issue to partials having their parents set the original function parent.
So in the [abbreviated] code from pylint/checkers/utils.py below,
func(partial(error_of_type, ...)) gets Module as the parent (and since it has the same name, PartialFunction(name=error_of_type)), both of these values are locals in Module with the same name. This lead to the extremely strange case oferror_of_type(handler, exception)inferred as botherror_of_typeandpartial(error_of_type, ...).The proper parent for
partial(error_of_type, ...)should just be the normal assignment tofunc.This also fixes the underlying issue seen in pylint-dev/pylint#2588 / 87b55a6e without a special case.
Type of Changes
Related Issue
pylint-dev/pylint#4357