-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4295df
commit ca9df0f
Showing
2 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""String utility functions.""" | ||
|
||
import sys | ||
|
||
|
||
def remove_prefix(text: str, prefix: str) -> str: | ||
"""Remove a prefix from a string, if present. | ||
This can be removed once we drop support for Python 3.8. | ||
Args: | ||
text: The string to remove the prefix from. | ||
prefix: The prefix to remove. | ||
Returns: | ||
The string with the prefix removed, if present. | ||
""" | ||
if sys.version_info >= (3, 9): | ||
return text.removeprefix(prefix) | ||
if text.startswith(prefix): | ||
return text[len(prefix) :] | ||
return text |