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

Apply infer_kwarg_from_call() to more checks #8775

Merged

Conversation

jacobtylerwalls
Copy link
Member

Closes #7761

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Follow-up to #8728, which created infer_kwarg_from_call(). I looked for other places we should use to close #7761.

These mostly solve false negatives for various checks, save for one false positive for use-maxsplit-arg. Not worth pulling it out to backport.

I did open a separate issue for #8774, though, because it's a crash fix we could backport.

Closes #7761

These mostly solve false negatives for various checks,
save for one false positive for `use-maxsplit-arg`.

Closes pylint-dev#7761
@jacobtylerwalls jacobtylerwalls added this to the 3.0.0a7 milestone Jun 13, 2023
@@ -2228,6 +2230,13 @@ def _check_unnecessary_list_index_lookup(
# is not redundant, hence we should not report an error.
return

# Preserve preliminary_confidence if it was INFERENCE
Copy link
Member Author

Choose a reason for hiding this comment

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

Not terribly important, but maybe someday a merge_confidence() helper would be a usability win.

Copy link
Member

Choose a reason for hiding this comment

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

What about a __add__ ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should just wait for #7121, when we might have a numeric level we can just compare directly.

@codecov
Copy link

codecov bot commented Jun 13, 2023

Codecov Report

Merging #8775 (840d1ab) into main (6fca823) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8775   +/-   ##
=======================================
  Coverage   95.83%   95.83%           
=======================================
  Files         173      173           
  Lines       18451    18459    +8     
=======================================
+ Hits        17683    17691    +8     
  Misses        768      768           
Impacted Files Coverage Ξ”
...int/checkers/refactoring/recommendation_checker.py 96.50% <100.00%> (+0.08%) ⬆️
pylint/checkers/refactoring/refactoring_checker.py 98.23% <100.00%> (+<0.01%) ⬆️
pylint/checkers/stdlib.py 96.77% <100.00%> (ΓΈ)

@github-actions
Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on pytest:
The following messages are now emitted:

  1. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/nodes.py#L374
  2. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/nodes.py#L508
  3. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/pytester.py#L125
  4. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/main.py#L633
  5. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/main.py#L686
  6. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/main.py#L690
  7. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/main.py#L763
  8. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/main.py#L862
  9. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/python.py#L348
  10. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/monkeypatch.py#L132
  11. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/monkeypatch.py#L133
  12. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/hookspec.py#L516
  13. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/python_api.py#L159
  14. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/python_api.py#L796
  15. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/python_api.py#L805
  16. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/junitxml.py#L487
  17. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/junitxml.py#L490
  18. deprecated-typing-alias:
    'typing.Callable' is deprecated, use 'collections.abc.Callable' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/config/__init__.py#L1012

The following messages are no longer emitted:

  1. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L89
  2. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L96
  3. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L101
  4. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L236
  5. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L360
  6. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L364
  7. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1139
  8. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1149
  9. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1181
  10. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1184
  11. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1492
  12. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/fixtures.py#L1492
  13. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/runner.py#L373
  14. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/runner.py#L470
  15. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/capture.py#L488
  16. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/pytester.py#L1074
  17. deprecated-typing-alias:
    'typing.Tuple' is deprecated, use 'tuple' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/reports.py#L256
  18. deprecated-typing-alias:
    'typing.Callable' is deprecated, use 'collections.abc.Callable' instead
    https://github.com/pytest-dev/pytest/blob/b7a142f4babddce76168e9cb00bf5de6b145c0e4/src/_pytest/_py/path.py#L142

This comment was generated for commit 840d1ab

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Just a nit, looks great !

try:
iterable_arg = utils.get_argument_from_call(
node.iter, position=0, keyword="iterable"
)
except utils.NoSuchArgumentError:
return
iterable_arg = utils.infer_kwarg_from_call(node.iter, keyword="iterable")
preliminary_confidence = INFERENCE
Copy link
Member

Choose a reason for hiding this comment

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

At this point it's not preliminary anymore so it c/sould be named confidence ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is preliminary if the second one turns out to be CONTROL_FLOW, was my thought. But then I should change the second condition to != HIGH.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, that's not quite right either. I guess I'd rather keep preliminary for now.

@@ -2228,6 +2230,13 @@ def _check_unnecessary_list_index_lookup(
# is not redundant, hence we should not report an error.
return

# Preserve preliminary_confidence if it was INFERENCE
Copy link
Member

Choose a reason for hiding this comment

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

What about a __add__ ?

@jacobtylerwalls jacobtylerwalls merged commit 507dfc5 into pylint-dev:main Jun 14, 2023
@jacobtylerwalls jacobtylerwalls deleted the various-false-negatives branch June 14, 2023 11:36
@jacobtylerwalls
Copy link
Member Author

Thanks for the review!

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.

get_argument_from_call doesn't account for **kwargs
2 participants