Skip to content

Commit 125843b

Browse files
committed
Put all regex patterns in r-strings
This improves consistency, because most were already. For a few it allows backslashes to removed, improving readability. Even for the others, some editors will highlight them as regular expressions now that they are raw string literals.
1 parent f9ccfba commit 125843b

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

Diff for: git/cmd.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class Git(LazyMixin):
264264

265265
_excluded_ = ("cat_file_all", "cat_file_header", "_version_info")
266266

267-
re_unsafe_protocol = re.compile("(.+)::.+")
267+
re_unsafe_protocol = re.compile(r"(.+)::.+")
268268

269269
def __getstate__(self) -> Dict[str, Any]:
270270
return slots_to_dict(self, exclude=self._excluded_)

Diff for: git/diff.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# Special object to compare against the empty tree in diffs
5454
NULL_TREE = object()
5555

56-
_octal_byte_re = re.compile(b"\\\\([0-9]{3})")
56+
_octal_byte_re = re.compile(rb"\\([0-9]{3})")
5757

5858

5959
def _octal_repl(matchobj: Match) -> bytes:

Diff for: git/refs/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]):
4141

4242
"""Named tuple allowing easy access to the revlog data fields"""
4343

44-
_re_hexsha_only = re.compile("^[0-9A-Fa-f]{40}$")
44+
_re_hexsha_only = re.compile(r"^[0-9A-Fa-f]{40}$")
4545
__slots__ = ()
4646

4747
def __repr__(self) -> str:

Diff for: git/repo/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class Repo(object):
131131

132132
# precompiled regex
133133
re_whitespace = re.compile(r"\s+")
134-
re_hexsha_only = re.compile("^[0-9A-Fa-f]{40}$")
135-
re_hexsha_shortened = re.compile("^[0-9A-Fa-f]{4,40}$")
134+
re_hexsha_only = re.compile(r"^[0-9A-Fa-f]{40}$")
135+
re_hexsha_shortened = re.compile(r"^[0-9A-Fa-f]{4,40}$")
136136
re_envvars = re.compile(r"(\$(\{\s?)?[a-zA-Z_]\w*(\}\s?)?|%\s?[a-zA-Z_]\w*\s?%)")
137137
re_author_committer_start = re.compile(r"^(author|committer)")
138138
re_tab_full_line = re.compile(r"^\t(.*)$")

Diff for: test/test_exc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_CommandError_unicode(self, case):
102102

103103
if subs is not None:
104104
# Substrings (must) already contain opening `'`.
105-
subs = "(?<!')%s(?!')" % re.escape(subs)
105+
subs = r"(?<!')%s(?!')" % re.escape(subs)
106106
self.assertRegex(s, subs)
107107

108108
if not stream:

0 commit comments

Comments
 (0)