File size: 10,080 Bytes
11c83cb
1
{"language": "Python", "id": 39, "repo_owner": "qtile", "repo_name": "qtile", "head_branch": "master", "workflow_name": "Run pre-commit", "workflow_filename": "pre_commit.yml", "workflow_path": ".github/workflows/pre_commit.yml", "contributor": "qtile", "sha_fail": "ac842d4dfb46538e2e59e77a0d52080a153df886", "sha_success": "5795ce0bf3300d05a871d466c973f47308beba45", "workflow": "name: Run pre-commit\n\non:\n    push:\n    pull_request:\n\njobs:\n    check:\n        runs-on: ubuntu-latest\n        steps:\n            - uses: actions/checkout@v4\n            - uses: actions/setup-python@v4\n            - name: Install dependencies\n              run: |\n                sudo apt update\n                sudo apt install --no-install-recommends libxkbcommon-dev\n            - uses: pre-commit/[email protected]\n", "logs": [{"step_name": "check/5_Run [email protected]", "log": "##[group]Run pre-commit/[email protected]\nwith:\n  extra_args: --all-files\n##[endgroup]\n##[group]Run python -m pip install pre-commit\n\u001b[36;1mpython -m pip install pre-commit\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\n##[endgroup]\nDefaulting to user installation because normal site-packages is not writeable\nCollecting pre-commit\n  Downloading pre_commit-3.5.0-py2.py3-none-any.whl (203 kB)\n     \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 203.7/203.7 KB 3.9 MB/s eta 0:00:00\nCollecting identify>=1.0.0\n  Downloading identify-2.5.31-py2.py3-none-any.whl (98 kB)\n     \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 98.9/98.9 KB 9.1 MB/s eta 0:00:00\nCollecting cfgv>=2.0.0\n  Downloading cfgv-3.4.0-py2.py3-none-any.whl (7.2 kB)\nRequirement already satisfied: pyyaml>=5.1 in /usr/lib/python3/dist-packages (from pre-commit) (5.4.1)\nCollecting virtualenv>=20.10.0\n  Downloading virtualenv-20.24.6-py3-none-any.whl (3.8 MB)\n     \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 3.8/3.8 MB 21.1 MB/s eta 0:00:00\nCollecting nodeenv>=0.11.1\n  Downloading nodeenv-1.8.0-py2.py3-none-any.whl (22 kB)\nRequirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from nodeenv>=0.11.1->pre-commit) (59.6.0)\nCollecting distlib<1,>=0.3.7\n  Downloading distlib-0.3.7-py2.py3-none-any.whl (468 kB)\n     \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 468.9/468.9 KB 37.7 MB/s eta 0:00:00\nCollecting platformdirs<4,>=3.9.1\n  Downloading platformdirs-3.11.0-py3-none-any.whl (17 kB)\nCollecting filelock<4,>=3.12.2\n  Downloading filelock-3.13.1-py3-none-any.whl (11 kB)\nInstalling collected packages: distlib, platformdirs, nodeenv, identify, filelock, cfgv, virtualenv, pre-commit\nSuccessfully installed cfgv-3.4.0 distlib-0.3.7 filelock-3.13.1 identify-2.5.31 nodeenv-1.8.0 platformdirs-3.11.0 pre-commit-3.5.0 virtualenv-20.24.6\n##[group]Run python -m pip freeze --local\n\u001b[36;1mpython -m pip freeze --local\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\n##[endgroup]\nargcomplete==3.1.2\ncfgv==3.4.0\ndistlib==0.3.7\nfilelock==3.13.1\nidentify==2.5.31\nnodeenv==1.8.0\npackaging==23.2\npipx==1.2.1\nplatformdirs==3.11.0\npre-commit==3.5.0\nuserpath==1.9.1\nvirtualenv==20.24.6\n##[group]Run actions/cache@v3\nwith:\n  path: ~/.cache/pre-commit\n  key: pre-commit-3||05c1fbbb63b353467651b511e6ac241ffd2d8e71749cfabfe5ee6bc8366d2d02\n  enableCrossOsArchive: false\n  fail-on-cache-miss: false\n  lookup-only: false\n##[endgroup]\nCache Size: ~36 MB (37431926 B)\n[command]/usr/bin/tar -xf /home/runner/work/_temp/197df8ad-dba5-43ca-8f9c-fc801b310ed7/cache.tzst -P -C /home/runner/work/qtile/qtile --use-compress-program unzstd\nReceived 37431926 of 37431926 (100.0%), 35.7 MBs/sec\nCache restored successfully\nCache restored from key: pre-commit-3||05c1fbbb63b353467651b511e6ac241ffd2d8e71749cfabfe5ee6bc8366d2d02\n##[group]Run pre-commit run --show-diff-on-failure --color=always --all-files\n\u001b[36;1mpre-commit run --show-diff-on-failure --color=always --all-files\u001b[0m\nshell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}\n##[endgroup]\nblack....................................................................\u001b[42mPassed\u001b[m\nisort....................................................................\u001b[42mPassed\u001b[m\nflake8...................................................................\u001b[42mPassed\u001b[m\nmypy.....................................................................\u001b[41mFailed\u001b[m\n\u001b[2m- hook id: mypy\u001b[m\n\u001b[2m- exit code: 1\u001b[m\n\nlibqtile/hook.py:107: error: Need type annotation for \"hooks\" (hint: \"hooks: Set[<type>] = ...\")  [var-annotated]\nlibqtile/hook.py:136: error: Return type \"None\" of \"_subscribe\" incompatible with return type \"Callable[..., Any]\" in supertype \"Subscribe\"  [override]\nlibqtile/bar.py:351: error: \"Subscribe\" has no attribute \"setgroup\"  [attr-defined]\nlibqtile/bar.py:352: error: \"Subscribe\" has no attribute \"startup_complete\"  [attr-defined]\nlibqtile/scratchpad.py:403: error: \"Subscribe\" has no attribute \"client_new\"  [attr-defined]\nlibqtile/scratchpad.py:407: error: \"Subscribe\" has no attribute \"client_killed\"  [attr-defined]\nlibqtile/scratchpad.py:408: error: \"Subscribe\" has no attribute \"float_change\"  [attr-defined]\nlibqtile/layout/screensplit.py:177: error: \"Subscribe\" has no attribute \"focus_change\"  [attr-defined]\nlibqtile/layout/screensplit.py:180: error: \"Unsubscribe\" has no attribute \"focus_change\"  [attr-defined]\nlibqtile/core/state.py:91: error: \"Subscribe\" has no attribute \"client_new\"  [attr-defined]\nlibqtile/core/state.py:110: error: \"Unsubscribe\" has no attribute \"client_new\"  [attr-defined]\nlibqtile/core/manager.py:177: error: \"Subscribe\" has no attribute \"setgroup\"  [attr-defined]\nlibqtile/core/manager.py:180: error: \"Subscribe\" has no attribute \"screen_change\"  [attr-defined]\nlibqtile/widget/prompt.py:412: error: \"Subscribe\" has no attribute \"client_focus\"  [attr-defined]\nlibqtile/backend/wayland/core.py:200: error: \"Subscribe\" has no attribute \"startup_complete\"  [attr-defined]\nFound 15 errors in 8 files (checked 178 source files)\n\nvulture..................................................................\u001b[42mPassed\u001b[m\n##[error]Process completed with exit code 1.\n"}], "diff": "diff --git a/libqtile/hook.py b/libqtile/hook.py\nindex f405a68d..da33d949 100644\n--- a/libqtile/hook.py\n+++ b/libqtile/hook.py\n@@ -42,6 +42,8 @@ from libqtile.resources.sleep import inhibitor\n if TYPE_CHECKING:\n     from typing import Callable\n \n+    HookHandler = Callable[[Callable], Callable]\n+\n subscriptions = {}  # type: dict\n \n \n@@ -87,7 +89,7 @@ def _user_hook_func(self):\n         def f(func):\n             name = f\"user_{hook_name}\"\n             if name not in self.hooks:\n-                self.hooks.add(name)\n+                self.hooks[name] = None\n             return self._subscribe(name, func)\n \n         return f\n@@ -102,15 +104,28 @@ class Hook:\n         self.func = func\n \n \n-class Subscribe:\n+class HookHandlerCollection:\n     def __init__(self, registry_name: str, check_name=True):\n-        self.hooks = set([])\n+        self.hooks: dict[str, HookHandler] = {}\n         if check_name and registry_name in subscriptions:\n             raise NameError(\"A hook registry already exists with that name: {registry_name}\")\n         elif registry_name not in subscriptions:\n             subscriptions[registry_name] = {}\n         self.registry_name = registry_name\n \n+    def __getattr__(self, name: str) -> HookHandler:\n+        if name not in self.hooks:\n+            raise AttributeError\n+        return self.hooks[name]\n+\n+    def _register(self, hook: Hook) -> None:\n+        def _hook_func(func):\n+            return self._subscribe(hook.name, func)\n+\n+        self.hooks[hook.name] = _hook_func if hook.func is None else hook.func(self)\n+\n+\n+class Subscribe(HookHandlerCollection):\n     def _subscribe(self, event: str, func: Callable) -> Callable:\n         registry = subscriptions.setdefault(self.registry_name, dict())\n         lst = registry.setdefault(event, [])\n@@ -118,16 +133,8 @@ class Subscribe:\n             lst.append(func)\n         return func\n \n-    def _register(self, hook: Hook) -> None:\n-        def _hook_func(func):\n-            return self._subscribe(hook.name, func)\n-\n-        self.hooks.add(hook.name)\n-        setattr(self, hook.name, _hook_func if hook.func is None else hook.func(self))\n-        setattr(getattr(self, hook.name), \"__doc__\", hook.doc)\n-\n \n-class Unsubscribe(Subscribe):\n+class Unsubscribe(HookHandlerCollection):\n     \"\"\"\n     This class mirrors subscribe, except the _subscribe member has been\n     overridden to remove calls from hooks.\n@@ -153,7 +160,7 @@ class Registry:\n             self.register_hook(hook)\n \n     def register_hook(self, hook: Hook) -> None:\n-        if hook.name in dir(self.subscribe):\n+        if hook.name in self.subscribe.hooks:\n             raise utils.QtileError(\n                 f\"Unable to register hook. A hook with that name already exists: {hook.name}\"\n             )\n", "difficulty": 2, "changed_files": ["libqtile/hook.py"], "commit_link": "https://github.com/qtile/qtile/tree/ac842d4dfb46538e2e59e77a0d52080a153df886"}