Skip to content

Commit a4c636c

Browse files
fix: use raw strings for regex (#95)
As of python/cpython#98401 (released in Python 3.12.0), invalid escape sequences emit louder warnings, as described in #89. This patch uses raw strings for compiled regexes to suppress the warnings.
1 parent df51155 commit a4c636c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

git-format-staged

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def format_file_in_index(formatter, diff_entry, update_working_tree=True, write=
8686

8787
return new_hash
8888

89-
file_path_placeholder = re.compile('\{\}')
89+
file_path_placeholder = re.compile(r'\{\}')
9090

9191
# Run formatter on a git blob identified by its hash. Writes output to a new git
9292
# blob, and returns the hash of the new blob.
@@ -167,7 +167,7 @@ def patch_working_file(path, orig_object_hash, new_object_hash):
167167
raise Exception('could not apply formatting changes to working tree file {}'.format(path))
168168

169169
# Format: src_mode dst_mode src_hash dst_hash status/score? src_path dst_path?
170-
diff_pat = re.compile('^:(\d+) (\d+) ([a-f0-9]+) ([a-f0-9]+) ([A-Z])(\d+)?\t([^\t]+)(?:\t([^\t]+))?$')
170+
diff_pat = re.compile(r'^:(\d+) (\d+) ([a-f0-9]+) ([a-f0-9]+) ([A-Z])(\d+)?\t([^\t]+)(?:\t([^\t]+))?$')
171171

172172
# Parse output from `git diff-index`
173173
def parse_diff(diff):
@@ -185,7 +185,7 @@ def parse_diff(diff):
185185
'dst_path': m.group(8)
186186
}
187187

188-
zeroed_pat = re.compile('^0+$')
188+
zeroed_pat = re.compile(r'^0+$')
189189

190190
# Returns the argument unless the argument is a string of zeroes, in which case
191191
# returns `None`

0 commit comments

Comments
 (0)