Closed
Description
Bug description
# File a.py
"""
The "global-variable-not-assigned" check does not take into account that a "with"
statement can very well change the global variable.
For example, when using a global condition variable by multiple threads:
"""
import threading
COND = threading.Condition()
def func1():
"Function that is called in one thread"
# pylint: disable=global-statement
global COND
with COND:
COND.notify()
Configuration
No response
Command used
pylint a.py
Pylint output
************* Module a
a.py:16:4: W0602: Using global for 'COND' but no assignment is done (global-variable-not-assigned)
Expected behavior
Pylint realizes that "with" may change the global variable and thus counts it like it was an assignment, and thus does not raise the issue in this case.
Pylint version
pylint 2.11.1
astroid 2.8.0
Python 3.9.7 (default, Sep 3 2021, 12:45:31)
[Clang 12.0.0 (clang-1200.0.32.29)]
OS / Environment
macOS
Additional dependencies
Output of pipdeptree:
pylint==1.6.4
- astroid [required: >=1.4.5,<1.5.0, installed: 1.4.9]
- lazy-object-proxy [required: Any, installed: 1.4.2]
- six [required: Any, installed: 1.15.0]
- wrapt [required: Any, installed: 1.11.2]
- backports.functools-lru-cache [required: Any, installed: 1.6.4]
- configparser [required: Any, installed: 4.0.2]
- isort [required: >=4.2.5, installed: 4.2.15]
- mccabe [required: Any, installed: 0.6.1]
- six [required: Any, installed: 1.15.0]