-
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Bug description
I am deliberately putting some logging statements interspersed with imports, as imports of some 3rd party libs take significant time and I am instrumenting that progress.
Import statements following non-import statements produce wrong-import-position, and I tried to suppress them precisely instead of disable globally or by block.
I found, accidentally, that if I disable=wrong-import-position for the non-import statement,
a. pylint correctly reports it as a useless-suppression
b. wrongly suppresses the subsequent wrong-import-position findings.
Command used
pylint --rcfile pylintrc --verbose --enable=useless-suppression --disable=C0301,W0311 ../demo_pylint.py
Pylint output
************* Module LabGym.demo_pylint /Users/john/Public/LabGym/LabGym/demo_pylint.py:7:0: I0021: Useless suppression of 'wrong-import-position' (useless-suppression)
Expected behavior
************* Module LabGym.demo_pylint
/Users/john/Public/LabGym/LabGym/demo_pylint.py:7:0: I0021: Useless suppression of 'wrong-import-position' (useless-suppression)
/Users/john/Public/LabGym/LabGym/demo_pylint.py:11:0: C0413: Import "import os" should be placed at the top of the module (wrong-import-position)
/Users/john/Public/LabGym/LabGym/demo_pylint.py:12:0: C0413: Import "import pathlib" should be placed at the top of the module (wrong-import-position)
/Users/john/Public/LabGym/LabGym/demo_pylint.py:13:0: C0413: Import "import random" should be placed at the top of the module (wrong-import-position)
Pylint version
pylint 3.3.7 astroid 3.3.11 Python 3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0 (clang-1300.0.29.30)]
OS / Environment
here is simple test case whose output was provided in this issue:
"""Demo""" import logging import sys # Xpylint: disable-next=wrong-import-position logger = logging.getLogger() # pylint: disable=wrong-import-position logging.basicConfig(level='DEBUG') logger.debug('import random (starting...)') import os import pathlib import random logger.debug('import random (done)') sys.argv() os.environ() pathlib.Path() random.random()