GeezerVison is showing github.com — python 3.9+: use removeprefix · pre-commit/pre-commit@08478ec
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pre_commit/languages/python.py +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -65,7 +65,7 @@ def _find_by_py_launcher( | 65 | 65 | version: str, | 66 | 66 | ) -> str | None: # pragma: no cover (windows only) | 67 | 67 | if version.startswith('python'): | 68 | | - num = version[len('python'):] | | 68 | + num = version.removeprefix('python') | 69 | 69 | cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)') | 70 | 70 | env = dict(os.environ, PYTHONIOENCODING='UTF-8') | 71 | 71 | try: | @@ -124,7 +124,7 @@ def _sys_executable_matches(version: str) -> bool: | 124 | 124 | return False | 125 | 125 |
| 126 | 126 | try: | 127 | | - info = tuple(int(p) for p in version[len('python'):].split('.')) | | 127 | + info = tuple(int(p) for p in version.removeprefix('python').split('.')) | 128 | 128 | except ValueError: | 129 | 129 | return False | 130 | 130 |
| |
Collapse file Copy file name to clipboardExpand all lines: pre_commit/languages/rust.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,7 +134,7 @@ def install_environment( | 134 | 134 |
| 135 | 135 | packages_to_install: set[tuple[str, ...]] = {('--path', '.')} | 136 | 136 | for cli_dep in cli_deps: | 137 | | - cli_dep = cli_dep[len('cli:'):] | | 137 | + cli_dep = cli_dep.removeprefix('cli:') | 138 | 138 | package, _, crate_version = cli_dep.partition(':') | 139 | 139 | if crate_version != '': | 140 | 140 | packages_to_install.add((package, '--version', crate_version)) | |
Collapse file Copy file name to clipboardExpand all lines: tests/commands/install_uninstall_test.py +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -349,8 +349,9 @@ def test_install_existing_hooks_no_overwrite(tempdir_factory, store): | 349 | 349 | # We should run both the legacy and pre-commit hooks | 350 | 350 | ret, output = _get_commit_output(tempdir_factory) | 351 | 351 | assert ret == 0 | 352 | | - assert output.startswith('legacy hook\n') | 353 | | - NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):]) | | 352 | + legacy = 'legacy hook\n' | | 353 | + assert output.startswith(legacy) | | 354 | + NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy)) | 354 | 355 |
| 355 | 356 |
| 356 | 357 | def test_legacy_overwriting_legacy_hook(tempdir_factory, store): | @@ -375,8 +376,9 @@ def test_install_existing_hook_no_overwrite_idempotent(tempdir_factory, store): | 375 | 376 | # We should run both the legacy and pre-commit hooks | 376 | 377 | ret, output = _get_commit_output(tempdir_factory) | 377 | 378 | assert ret == 0 | 378 | | - assert output.startswith('legacy hook\n') | 379 | | - NORMAL_PRE_COMMIT_RUN.assert_matches(output[len('legacy hook\n'):]) | | 379 | + legacy = 'legacy hook\n' | | 380 | + assert output.startswith(legacy) | | 381 | + NORMAL_PRE_COMMIT_RUN.assert_matches(output.removeprefix(legacy)) | 380 | 382 |
| 381 | 383 |
| 382 | 384 | def test_install_with_existing_non_utf8_script(tmpdir, store): | |
Collapse file Copy file name to clipboardExpand all lines: tests/store_test.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -185,7 +185,7 @@ def test_db_repo_name(store): | 185 | 185 |
| 186 | 186 | def test_local_resources_reflects_reality(): | 187 | 187 | on_disk = { | 188 | | - res[len('empty_template_'):] | | 188 | + res.removeprefix('empty_template_') | 189 | 189 | for res in os.listdir('pre_commit/resources') | 190 | 190 | if res.startswith('empty_template_') | 191 | 191 | } | |
|