diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-05-20 11:08:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-20 11:08:28 (GMT) |
commit | 663c049ff78a299bdf7c1a0444b9900e6d37372d (patch) | |
tree | 00df391540dfbb2abeeb04c0dbc9967dae1f96c7 | |
parent | ae147d01a005e0a65510a605762d1ff79f3affb9 (diff) | |
download | cpython-663c049ff78a299bdf7c1a0444b9900e6d37372d.zip cpython-663c049ff78a299bdf7c1a0444b9900e6d37372d.tar.gz cpython-663c049ff78a299bdf7c1a0444b9900e6d37372d.tar.bz2 |
gh-104683: Modernise `clinic.py` using `str.removeprefix` and `str.removesuffix` (#104685)
Both methods were new in Python 3.9.
-rwxr-xr-x | Tools/clinic/clinic.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 792e8e4..b00b480 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1741,7 +1741,7 @@ class BlockParser: # make sure to recognize stop line even if it # doesn't end with EOL (it could be the very end of the file) if line.startswith(stop_line): - remainder = line[len(stop_line):] + remainder = line.removeprefix(stop_line) if remainder and not remainder.isspace(): fail(f"Garbage after stop line: {remainder!r}") return True @@ -1759,7 +1759,7 @@ class BlockParser: if body_prefix: line = line.lstrip() assert line.startswith(body_prefix) - line = line[len(body_prefix):] + line = line.removeprefix(body_prefix) input_add(line) # consume output and checksum line, if present. @@ -2562,7 +2562,7 @@ def add_c_converter(f, name=None): name = f.__name__ if not name.endswith('_converter'): return f - name = name[:-len('_converter')] + name = name.removesuffix('_converter') converters[name] = f return f @@ -3969,7 +3969,7 @@ def add_c_return_converter(f, name=None): name = f.__name__ if not name.endswith('_return_converter'): return f - name = name[:-len('_return_converter')] + name = name.removesuffix('_return_converter') return_converters[name] = f return f @@ -5360,7 +5360,7 @@ For more information see https://docs.python.org/3/howto/clinic.html""") if name in ignored: continue if name.endswith(suffix): - ids.append((name, name[:-len(suffix)])) + ids.append((name, name.removesuffix(suffix))) break print() |