We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v2.25.0 → v2.26.0](https://github.com/asottile/pyupgrade/compare/v2.25.0...v2.26.0)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/commands/install_uninstall.py`
Content:
```
1 import itertools
2 import logging
3 import os.path
4 import shutil
5 import sys
6 from typing import Optional
7 from typing import Sequence
8 from typing import Tuple
9 
10 from pre_commit import git
11 from pre_commit import output
12 from pre_commit.clientlib import load_config
13 from pre_commit.repository import all_hooks
14 from pre_commit.repository import install_hook_envs
15 from pre_commit.store import Store
16 from pre_commit.util import make_executable
17 from pre_commit.util import resource_text
18 
19 
20 logger = logging.getLogger(__name__)
21 
22 # This is used to identify the hook file we install
23 PRIOR_HASHES = (
24     b'4d9958c90bc262f47553e2c073f14cfe',
25     b'd8ee923c46731b42cd95cc869add4062',
26     b'49fd668cb42069aa1b6048464be5d395',
27     b'79f09a650522a87b0da915d0d983b2de',
28     b'e358c9dae00eac5d06b38dfdb1e33a8c',
29 )
30 CURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03'
31 TEMPLATE_START = '# start templated\n'
32 TEMPLATE_END = '# end templated\n'
33 # Homebrew/homebrew-core#35825: be more timid about appropriate `PATH`
34 # #1312 os.defpath is too restrictive on BSD
35 POSIX_SEARCH_PATH = ('/usr/local/bin', '/usr/bin', '/bin')
36 SYS_EXE = os.path.basename(os.path.realpath(sys.executable))
37 
38 
39 def _hook_paths(
40         hook_type: str,
41         git_dir: Optional[str] = None,
42 ) -> Tuple[str, str]:
43     git_dir = git_dir if git_dir is not None else git.get_git_dir()
44     pth = os.path.join(git_dir, 'hooks', hook_type)
45     return pth, f'{pth}.legacy'
46 
47 
48 def is_our_script(filename: str) -> bool:
49     if not os.path.exists(filename):  # pragma: win32 no cover (symlink)
50         return False
51     with open(filename, 'rb') as f:
52         contents = f.read()
53     return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
54 
55 
56 def shebang() -> str:
57     if sys.platform == 'win32':
58         py, _ = os.path.splitext(SYS_EXE)
59     else:
60         exe_choices = [
61             f'python{sys.version_info[0]}.{sys.version_info[1]}',
62             f'python{sys.version_info[0]}',
63         ]
64         # avoid searching for bare `python` as it's likely to be python 2
65         if SYS_EXE != 'python':
66             exe_choices.append(SYS_EXE)
67         for path, exe in itertools.product(POSIX_SEARCH_PATH, exe_choices):
68             if os.access(os.path.join(path, exe), os.X_OK):
69                 py = exe
70                 break
71         else:
72             py = SYS_EXE
73     return f'#!/usr/bin/env {py}'
74 
75 
76 def _install_hook_script(
77         config_file: str,
78         hook_type: str,
79         overwrite: bool = False,
80         skip_on_missing_config: bool = False,
81         git_dir: Optional[str] = None,
82 ) -> None:
83     hook_path, legacy_path = _hook_paths(hook_type, git_dir=git_dir)
84 
85     os.makedirs(os.path.dirname(hook_path), exist_ok=True)
86 
87     # If we have an existing hook, move it to pre-commit.legacy
88     if os.path.lexists(hook_path) and not is_our_script(hook_path):
89         shutil.move(hook_path, legacy_path)
90 
91     # If we specify overwrite, we simply delete the legacy file
92     if overwrite and os.path.exists(legacy_path):
93         os.remove(legacy_path)
94     elif os.path.exists(legacy_path):
95         output.write_line(
96             f'Running in migration mode with existing hooks at {legacy_path}\n'
97             f'Use -f to use only pre-commit.',
98         )
99 
100     args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}']
101     if skip_on_missing_config:
102         args.append('--skip-on-missing-config')
103     params = {'INSTALL_PYTHON': sys.executable, 'ARGS': args}
104 
105     with open(hook_path, 'w') as hook_file:
106         contents = resource_text('hook-tmpl')
107         before, rest = contents.split(TEMPLATE_START)
108         to_template, after = rest.split(TEMPLATE_END)
109 
110         before = before.replace('#!/usr/bin/env python3', shebang())
111 
112         hook_file.write(before + TEMPLATE_START)
113         for line in to_template.splitlines():
114             var = line.split()[0]
115             hook_file.write(f'{var} = {params[var]!r}\n')
116         hook_file.write(TEMPLATE_END + after)
117     make_executable(hook_path)
118 
119     output.write_line(f'pre-commit installed at {hook_path}')
120 
121 
122 def install(
123         config_file: str,
124         store: Store,
125         hook_types: Sequence[str],
126         overwrite: bool = False,
127         hooks: bool = False,
128         skip_on_missing_config: bool = False,
129         git_dir: Optional[str] = None,
130 ) -> int:
131     if git_dir is None and git.has_core_hookpaths_set():
132         logger.error(
133             'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
134             'hint: `git config --unset-all core.hooksPath`',
135         )
136         return 1
137 
138     for hook_type in hook_types:
139         _install_hook_script(
140             config_file, hook_type,
141             overwrite=overwrite,
142             skip_on_missing_config=skip_on_missing_config,
143             git_dir=git_dir,
144         )
145 
146     if hooks:
147         install_hooks(config_file, store)
148 
149     return 0
150 
151 
152 def install_hooks(config_file: str, store: Store) -> int:
153     install_hook_envs(all_hooks(load_config(config_file), store), store)
154     return 0
155 
156 
157 def _uninstall_hook_script(hook_type: str) -> None:
158     hook_path, legacy_path = _hook_paths(hook_type)
159 
160     # If our file doesn't exist or it isn't ours, gtfo.
161     if not os.path.exists(hook_path) or not is_our_script(hook_path):
162         return
163 
164     os.remove(hook_path)
165     output.write_line(f'{hook_type} uninstalled')
166 
167     if os.path.exists(legacy_path):
168         os.replace(legacy_path, hook_path)
169         output.write_line(f'Restored previous hooks to {hook_path}')
170 
171 
172 def uninstall(hook_types: Sequence[str]) -> int:
173     for hook_type in hook_types:
174         _uninstall_hook_script(hook_type)
175     return 0
176
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py
--- a/pre_commit/commands/install_uninstall.py
+++ b/pre_commit/commands/install_uninstall.py
@@ -1,6 +1,7 @@
 import itertools
 import logging
 import os.path
+import shlex
 import shutil
 import sys
 from typing import Optional
@@ -100,19 +101,17 @@
     args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}']
     if skip_on_missing_config:
         args.append('--skip-on-missing-config')
-    params = {'INSTALL_PYTHON': sys.executable, 'ARGS': args}
 
     with open(hook_path, 'w') as hook_file:
         contents = resource_text('hook-tmpl')
         before, rest = contents.split(TEMPLATE_START)
-        to_template, after = rest.split(TEMPLATE_END)
-
-        before = before.replace('#!/usr/bin/env python3', shebang())
+        _, after = rest.split(TEMPLATE_END)
 
         hook_file.write(before + TEMPLATE_START)
-        for line in to_template.splitlines():
-            var = line.split()[0]
-            hook_file.write(f'{var} = {params[var]!r}\n')
+        hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n')
+        # TODO: python3.8+: shlex.join
+        args_s = ' '.join(shlex.quote(part) for part in args)
+        hook_file.write(f'ARGS=({args_s})\n')
         hook_file.write(TEMPLATE_END + after)
     make_executable(hook_path)

{"golden_diff": "diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py\n--- a/pre_commit/commands/install_uninstall.py\n+++ b/pre_commit/commands/install_uninstall.py\n@@ -1,6 +1,7 @@\n import itertools\n import logging\n import os.path\n+import shlex\n import shutil\n import sys\n from typing import Optional\n@@ -100,19 +101,17 @@\n     args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}']\n     if skip_on_missing_config:\n         args.append('--skip-on-missing-config')\n-    params = {'INSTALL_PYTHON': sys.executable, 'ARGS': args}\n \n     with open(hook_path, 'w') as hook_file:\n         contents = resource_text('hook-tmpl')\n         before, rest = contents.split(TEMPLATE_START)\n-        to_template, after = rest.split(TEMPLATE_END)\n-\n-        before = before.replace('#!/usr/bin/env python3', shebang())\n+        _, after = rest.split(TEMPLATE_END)\n \n         hook_file.write(before + TEMPLATE_START)\n-        for line in to_template.splitlines():\n-            var = line.split()[0]\n-            hook_file.write(f'{var} = {params[var]!r}\\n')\n+        hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\\n')\n+        # TODO: python3.8+: shlex.join\n+        args_s = ' '.join(shlex.quote(part) for part in args)\n+        hook_file.write(f'ARGS=({args_s})\\n')\n         hook_file.write(TEMPLATE_END + after)\n     make_executable(hook_path)\n", "issue": "[pre-commit.ci] pre-commit autoupdate\nupdates:\n- [github.com/asottile/pyupgrade: v2.25.0 \u2192 v2.26.0](https://github.com/asottile/pyupgrade/compare/v2.25.0...v2.26.0)\n\n", "before_files": [{"content": "import itertools\nimport logging\nimport os.path\nimport shutil\nimport sys\nfrom typing import Optional\nfrom typing import Sequence\nfrom typing import Tuple\n\nfrom pre_commit import git\nfrom pre_commit import output\nfrom pre_commit.clientlib import load_config\nfrom pre_commit.repository import all_hooks\nfrom pre_commit.repository import install_hook_envs\nfrom pre_commit.store import Store\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import resource_text\n\n\nlogger = logging.getLogger(__name__)\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    b'4d9958c90bc262f47553e2c073f14cfe',\n    b'd8ee923c46731b42cd95cc869add4062',\n    b'49fd668cb42069aa1b6048464be5d395',\n    b'79f09a650522a87b0da915d0d983b2de',\n    b'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n# Homebrew/homebrew-core#35825: be more timid about appropriate `PATH`\n# #1312 os.defpath is too restrictive on BSD\nPOSIX_SEARCH_PATH = ('/usr/local/bin', '/usr/bin', '/bin')\nSYS_EXE = os.path.basename(os.path.realpath(sys.executable))\n\n\ndef _hook_paths(\n        hook_type: str,\n        git_dir: Optional[str] = None,\n) -> Tuple[str, str]:\n    git_dir = git_dir if git_dir is not None else git.get_git_dir()\n    pth = os.path.join(git_dir, 'hooks', hook_type)\n    return pth, f'{pth}.legacy'\n\n\ndef is_our_script(filename: str) -> bool:\n    if not os.path.exists(filename):  # pragma: win32 no cover (symlink)\n        return False\n    with open(filename, 'rb') as f:\n        contents = f.read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef shebang() -> str:\n    if sys.platform == 'win32':\n        py, _ = os.path.splitext(SYS_EXE)\n    else:\n        exe_choices = [\n            f'python{sys.version_info[0]}.{sys.version_info[1]}',\n            f'python{sys.version_info[0]}',\n        ]\n        # avoid searching for bare `python` as it's likely to be python 2\n        if SYS_EXE != 'python':\n            exe_choices.append(SYS_EXE)\n        for path, exe in itertools.product(POSIX_SEARCH_PATH, exe_choices):\n            if os.access(os.path.join(path, exe), os.X_OK):\n                py = exe\n                break\n        else:\n            py = SYS_EXE\n    return f'#!/usr/bin/env {py}'\n\n\ndef _install_hook_script(\n        config_file: str,\n        hook_type: str,\n        overwrite: bool = False,\n        skip_on_missing_config: bool = False,\n        git_dir: Optional[str] = None,\n) -> None:\n    hook_path, legacy_path = _hook_paths(hook_type, git_dir=git_dir)\n\n    os.makedirs(os.path.dirname(hook_path), exist_ok=True)\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        shutil.move(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            f'Running in migration mode with existing hooks at {legacy_path}\\n'\n            f'Use -f to use only pre-commit.',\n        )\n\n    args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}']\n    if skip_on_missing_config:\n        args.append('--skip-on-missing-config')\n    params = {'INSTALL_PYTHON': sys.executable, 'ARGS': args}\n\n    with open(hook_path, 'w') as hook_file:\n        contents = resource_text('hook-tmpl')\n        before, rest = contents.split(TEMPLATE_START)\n        to_template, after = rest.split(TEMPLATE_END)\n\n        before = before.replace('#!/usr/bin/env python3', shebang())\n\n        hook_file.write(before + TEMPLATE_START)\n        for line in to_template.splitlines():\n            var = line.split()[0]\n            hook_file.write(f'{var} = {params[var]!r}\\n')\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line(f'pre-commit installed at {hook_path}')\n\n\ndef install(\n        config_file: str,\n        store: Store,\n        hook_types: Sequence[str],\n        overwrite: bool = False,\n        hooks: bool = False,\n        skip_on_missing_config: bool = False,\n        git_dir: Optional[str] = None,\n) -> int:\n    if git_dir is None and git.has_core_hookpaths_set():\n        logger.error(\n            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n            'hint: `git config --unset-all core.hooksPath`',\n        )\n        return 1\n\n    for hook_type in hook_types:\n        _install_hook_script(\n            config_file, hook_type,\n            overwrite=overwrite,\n            skip_on_missing_config=skip_on_missing_config,\n            git_dir=git_dir,\n        )\n\n    if hooks:\n        install_hooks(config_file, store)\n\n    return 0\n\n\ndef install_hooks(config_file: str, store: Store) -> int:\n    install_hook_envs(all_hooks(load_config(config_file), store), store)\n    return 0\n\n\ndef _uninstall_hook_script(hook_type: str) -> None:\n    hook_path, legacy_path = _hook_paths(hook_type)\n\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return\n\n    os.remove(hook_path)\n    output.write_line(f'{hook_type} uninstalled')\n\n    if os.path.exists(legacy_path):\n        os.replace(legacy_path, hook_path)\n        output.write_line(f'Restored previous hooks to {hook_path}')\n\n\ndef uninstall(hook_types: Sequence[str]) -> int:\n    for hook_type in hook_types:\n        _uninstall_hook_script(hook_type)\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}], "after_files": [{"content": "import itertools\nimport logging\nimport os.path\nimport shlex\nimport shutil\nimport sys\nfrom typing import Optional\nfrom typing import Sequence\nfrom typing import Tuple\n\nfrom pre_commit import git\nfrom pre_commit import output\nfrom pre_commit.clientlib import load_config\nfrom pre_commit.repository import all_hooks\nfrom pre_commit.repository import install_hook_envs\nfrom pre_commit.store import Store\nfrom pre_commit.util import make_executable\nfrom pre_commit.util import resource_text\n\n\nlogger = logging.getLogger(__name__)\n\n# This is used to identify the hook file we install\nPRIOR_HASHES = (\n    b'4d9958c90bc262f47553e2c073f14cfe',\n    b'd8ee923c46731b42cd95cc869add4062',\n    b'49fd668cb42069aa1b6048464be5d395',\n    b'79f09a650522a87b0da915d0d983b2de',\n    b'e358c9dae00eac5d06b38dfdb1e33a8c',\n)\nCURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03'\nTEMPLATE_START = '# start templated\\n'\nTEMPLATE_END = '# end templated\\n'\n# Homebrew/homebrew-core#35825: be more timid about appropriate `PATH`\n# #1312 os.defpath is too restrictive on BSD\nPOSIX_SEARCH_PATH = ('/usr/local/bin', '/usr/bin', '/bin')\nSYS_EXE = os.path.basename(os.path.realpath(sys.executable))\n\n\ndef _hook_paths(\n        hook_type: str,\n        git_dir: Optional[str] = None,\n) -> Tuple[str, str]:\n    git_dir = git_dir if git_dir is not None else git.get_git_dir()\n    pth = os.path.join(git_dir, 'hooks', hook_type)\n    return pth, f'{pth}.legacy'\n\n\ndef is_our_script(filename: str) -> bool:\n    if not os.path.exists(filename):  # pragma: win32 no cover (symlink)\n        return False\n    with open(filename, 'rb') as f:\n        contents = f.read()\n    return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)\n\n\ndef shebang() -> str:\n    if sys.platform == 'win32':\n        py, _ = os.path.splitext(SYS_EXE)\n    else:\n        exe_choices = [\n            f'python{sys.version_info[0]}.{sys.version_info[1]}',\n            f'python{sys.version_info[0]}',\n        ]\n        # avoid searching for bare `python` as it's likely to be python 2\n        if SYS_EXE != 'python':\n            exe_choices.append(SYS_EXE)\n        for path, exe in itertools.product(POSIX_SEARCH_PATH, exe_choices):\n            if os.access(os.path.join(path, exe), os.X_OK):\n                py = exe\n                break\n        else:\n            py = SYS_EXE\n    return f'#!/usr/bin/env {py}'\n\n\ndef _install_hook_script(\n        config_file: str,\n        hook_type: str,\n        overwrite: bool = False,\n        skip_on_missing_config: bool = False,\n        git_dir: Optional[str] = None,\n) -> None:\n    hook_path, legacy_path = _hook_paths(hook_type, git_dir=git_dir)\n\n    os.makedirs(os.path.dirname(hook_path), exist_ok=True)\n\n    # If we have an existing hook, move it to pre-commit.legacy\n    if os.path.lexists(hook_path) and not is_our_script(hook_path):\n        shutil.move(hook_path, legacy_path)\n\n    # If we specify overwrite, we simply delete the legacy file\n    if overwrite and os.path.exists(legacy_path):\n        os.remove(legacy_path)\n    elif os.path.exists(legacy_path):\n        output.write_line(\n            f'Running in migration mode with existing hooks at {legacy_path}\\n'\n            f'Use -f to use only pre-commit.',\n        )\n\n    args = ['hook-impl', f'--config={config_file}', f'--hook-type={hook_type}']\n    if skip_on_missing_config:\n        args.append('--skip-on-missing-config')\n\n    with open(hook_path, 'w') as hook_file:\n        contents = resource_text('hook-tmpl')\n        before, rest = contents.split(TEMPLATE_START)\n        _, after = rest.split(TEMPLATE_END)\n\n        hook_file.write(before + TEMPLATE_START)\n        hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\\n')\n        # TODO: python3.8+: shlex.join\n        args_s = ' '.join(shlex.quote(part) for part in args)\n        hook_file.write(f'ARGS=({args_s})\\n')\n        hook_file.write(TEMPLATE_END + after)\n    make_executable(hook_path)\n\n    output.write_line(f'pre-commit installed at {hook_path}')\n\n\ndef install(\n        config_file: str,\n        store: Store,\n        hook_types: Sequence[str],\n        overwrite: bool = False,\n        hooks: bool = False,\n        skip_on_missing_config: bool = False,\n        git_dir: Optional[str] = None,\n) -> int:\n    if git_dir is None and git.has_core_hookpaths_set():\n        logger.error(\n            'Cowardly refusing to install hooks with `core.hooksPath` set.\\n'\n            'hint: `git config --unset-all core.hooksPath`',\n        )\n        return 1\n\n    for hook_type in hook_types:\n        _install_hook_script(\n            config_file, hook_type,\n            overwrite=overwrite,\n            skip_on_missing_config=skip_on_missing_config,\n            git_dir=git_dir,\n        )\n\n    if hooks:\n        install_hooks(config_file, store)\n\n    return 0\n\n\ndef install_hooks(config_file: str, store: Store) -> int:\n    install_hook_envs(all_hooks(load_config(config_file), store), store)\n    return 0\n\n\ndef _uninstall_hook_script(hook_type: str) -> None:\n    hook_path, legacy_path = _hook_paths(hook_type)\n\n    # If our file doesn't exist or it isn't ours, gtfo.\n    if not os.path.exists(hook_path) or not is_our_script(hook_path):\n        return\n\n    os.remove(hook_path)\n    output.write_line(f'{hook_type} uninstalled')\n\n    if os.path.exists(legacy_path):\n        os.replace(legacy_path, hook_path)\n        output.write_line(f'Restored previous hooks to {hook_path}')\n\n\ndef uninstall(hook_types: Sequence[str]) -> int:\n    for hook_type in hook_types:\n        _uninstall_hook_script(hook_type)\n    return 0\n", "path": "pre_commit/commands/install_uninstall.py"}]}