Skip to content

Commit ffcbf07

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 7dd2095 commit ffcbf07

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

git/cmd.py

Lines changed: 1 addition & 1 deletion
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_)

git/diff.py

Lines changed: 1 addition & 1 deletion
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:

git/refs/log.py

Lines changed: 1 addition & 1 deletion
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:

git/repo/base.py

Lines changed: 2 additions & 2 deletions
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(.*)$")

test/test_exc.py

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy