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

PyLint's useless-suppression is not producing consistent behaviour with mock.patch.multiple_targets #8977

Closed
nbro10 opened this issue Aug 25, 2023 · 3 comments
Labels
Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine

Comments

@nbro10
Copy link

nbro10 commented Aug 25, 2023

Bug description

So, in my tests, I have something like this

from unittest import mock

def whatever():
    mocks = mock.patch.multiple_targets(  # pylint: disable=no-member
        [
            mock.patch(MODULE_PATH + '.func1),
            mock.patch(MODULE_PATH + '.func2'),
        ]
    )

If I run pylint with the suppression enabled, sometimes, it tells me that this disable is useless. So, I tried to remove it, but then I always get the error that multiple_targets is not a member

E1101: Function 'patch' has no 'multiple_targets' member (no-member)

The weirdest thing is that the useless suppression warning doesn't always happen or happens for different files

Configuration

Python 3.8.13

Command used

poetry run pylint my_package tests docs scripts --enable=useless-suppression

Pylint output

E1101: Function 'patch' has no 'multiple_targets' member (no-member)

Or

I0021: Useless suppression of 'no-member' (useless-suppression)

Expected behavior

PyLint is consistent

Pylint version

PyLint 2.14.5
Python 3.8.13
Astroid 2.11.7

OS / Environment

Mac OS Monterey, Apple M1

@nbro10 nbro10 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 25, 2023
@Pierre-Sassoulas
Copy link
Member

By sometime do you mean in the same environment when calling pylint multiple time ? Or are you using multiple interpreters or multiple environments (differing dependencies, OS, etc) ? Also you could upgrade pylint to 3.0.0a7 to see if the problem still exists :)

@Pierre-Sassoulas Pierre-Sassoulas added the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label Aug 25, 2023
@nbro10
Copy link
Author

nbro10 commented Aug 25, 2023

@Pierre-Sassoulas The exact same environment but with different command executions (where the command is poetry run pylint my_package tests docs scripts --enable=useless-suppression) - nothing else changes, just different executions of the same command can lead to different outputs (warning and no warning). I can't still upgrade pylint to the latest version because it's incompatible with Python 3.7, which my packages still supports (although we'll soon remove that support). This behaviour is really strange. This probably happening, I would guess, because something is not deterministic. Maybe the way the AST is parsed or the order of the execution of pylint on the different files.

@Pierre-Sassoulas
Copy link
Member

So if I understand you well you launch once with --enable=useless-suppression and the other without ? The code you gave is not parseable (a.py:7:38: E0001: Parsing failed: 'unterminated string literal (detected at line 7) (<unknown>, line 7)' (syntax-error)) so I parsed the following using both option:

from pathlib import Path
from unittest import mock

MODULE_PATH = Path(__file__)

def whatever():
    mocks = mock.patch.multiple_targets(  # pylint: disable=no-member
        [
            mock.patch(MODULE_PATH + '.func1'),
            mock.patch(MODULE_PATH + '.func2'),
        ]
    )

I don't have any issues on main / python 3.11 with this snippet. We did change a lot of things since 2.14, and some for useless-suppression (maybe #7887 in 2.15, but there might be others), so it's probable it was fixed on main and sadly we don't support python 3.7 anymore. Please reopen an issue if you have a reproducer for more recent version of pylint.

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2023
@Pierre-Sassoulas Pierre-Sassoulas removed the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine
Projects
None yet
Development

No branches or pull requests

2 participants