PHP 8.2.31
Preview: threading_checker.py Size: 1.90 KB
//opt/cloudlinux/venv/lib64/python3.11/site-packages/pylint/checkers/threading_checker.py

# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

from __future__ import annotations

from typing import TYPE_CHECKING

from astroid import nodes

from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages, safe_infer

if TYPE_CHECKING:
    from pylint.lint import PyLinter


class ThreadingChecker(BaseChecker):
    """Checks for threading module.

    - useless with lock - locking used in wrong way that has no effect (with threading.Lock():)
    """

    name = "threading"

    LOCKS = frozenset(
        (
            "threading.Lock",
            "threading.RLock",
            "threading.Condition",
            "threading.Semaphore",
            "threading.BoundedSemaphore",
        )
    )

    msgs = {
        "W2101": (
            "'%s()' directly created in 'with' has no effect",
            "useless-with-lock",
            "Used when a new lock instance is created by using with statement "
            "which has no effect. Instead, an existing instance should be used to acquire lock.",
        ),
    }

    @only_required_for_messages("useless-with-lock")
    def visit_with(self, node: nodes.With) -> None:
        context_managers = (c for c, _ in node.items if isinstance(c, nodes.Call))
        for context_manager in context_managers:
            if isinstance(context_manager, nodes.Call):
                infered_function = safe_infer(context_manager.func)
                if infered_function is None:
                    continue
                qname = infered_function.qname()
                if qname in self.LOCKS:
                    self.add_message("useless-with-lock", node=node, args=qname)


def register(linter: PyLinter) -> None:
    linter.register_checker(ThreadingChecker(linter))

Directory Contents

Dirs: 4 × Files: 31

Name Size Perms Modified Actions
base DIR
- drwxr-xr-x 2026-02-05 08:01:15
Edit Download
classes DIR
- drwxr-xr-x 2026-02-05 08:01:15
Edit Download
- drwxr-xr-x 2026-02-05 08:01:15
Edit Download
- drwxr-xr-x 2026-02-05 08:01:15
Edit Download
3.83 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
10.67 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
9.43 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
21.62 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.43 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.97 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
26.05 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
26.91 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
41.31 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.38 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
15.84 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.08 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.68 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.87 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
7.67 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.63 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.46 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
6.98 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
3.81 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
33.29 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
16.17 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
31.28 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
40.28 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.90 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
86.83 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
18.05 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
2.93 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
77.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
126.57 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
4.26 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).