Skip to content

Commit e0bc147

Browse files
gh-133306: Use \z instead of \Z in regular expressions in the stdlib
1 parent 77c391a commit e0bc147

File tree

16 files changed

+23
-23
lines changed

16 files changed

+23
-23
lines changed

Lib/_py_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _setoption(arg):
371371
if message:
372372
message = re.escape(message)
373373
if module:
374-
module = re.escape(module) + r'\Z'
374+
module = re.escape(module) + r'\z'
375375
if lineno:
376376
try:
377377
lineno = int(lineno)

Lib/_pydecimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6096,7 +6096,7 @@ def _convert_for_comparison(self, other, equality_op=False):
60966096
(?P<diag>\d*) # with (possibly empty) diagnostic info.
60976097
)
60986098
# \s*
6099-
\Z
6099+
\z
61006100
""", re.VERBOSE | re.IGNORECASE).match
61016101

61026102
_all_zeros = re.compile('0*$').match
@@ -6124,7 +6124,7 @@ def _convert_for_comparison(self, other, equality_op=False):
61246124
(?P<thousands_sep>[,_])?
61256125
(?:\.(?P<precision>0|(?!0)\d+))?
61266126
(?P<type>[eEfFgGn%])?
6127-
\Z
6127+
\z
61286128
""", re.VERBOSE|re.DOTALL)
61296129

61306130
del re

Lib/email/feedparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
NLCRE = re.compile(r'\r\n|\r|\n')
3232
NLCRE_bol = re.compile(r'(\r\n|\r|\n)')
33-
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
33+
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\z')
3434
NLCRE_crack = re.compile(r'(\r\n|\r|\n)')
3535
# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
3636
# except controls, SP, and ":".

Lib/fractions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _hash_algorithm(numerator, denominator):
6464
(?:\.(?P<decimal>\d*|\d+(_\d+)*))? # an optional fractional part
6565
(?:E(?P<exp>[-+]?\d+(_\d+)*))? # and optional exponent
6666
)
67-
\s*\Z # and optional whitespace to finish
67+
\s*\z # and optional whitespace to finish
6868
""", re.VERBOSE | re.IGNORECASE)
6969

7070

Lib/idlelib/pyshell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ def recall(self, s, event):
13501350
self.text.see("insert")
13511351
self.text.undo_block_stop()
13521352

1353-
_last_newline_re = re.compile(r"[ \t]*(\n[ \t]*)?\Z")
1353+
_last_newline_re = re.compile(r"[ \t]*(\n[ \t]*)?\z")
13541354
def runit(self):
13551355
index_before = self.text.index("end-2c")
13561356
line = self.text.get("iomark", "end-1c")

Lib/test/test_asyncio/test_locks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
r'(, value:\d)?'
1515
r'(, waiters:\d+)?'
1616
r'(, waiters:\d+\/\d+)?' # barrier
17-
r')\]>\Z'
17+
r')\]>\z'
1818
)
1919
RGX_REPR = re.compile(STR_RGX_REPR)
2020

Lib/test/test_gc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def func():
300300
# We're mostly just checking that this doesn't crash.
301301
rc, stdout, stderr = assert_python_ok("-c", code)
302302
self.assertEqual(rc, 0)
303-
self.assertRegex(stdout, rb"""\A\s*func=<function at \S+>\s*\Z""")
303+
self.assertRegex(stdout, rb"""\A\s*func=<function at \S+>\s*\z""")
304304
self.assertFalse(stderr)
305305

306306
@refcount_test

Lib/test/test_import/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def test_script_shadowing_third_party(self):
10011001

10021002
expected_error = error + (
10031003
rb" \(consider renaming '.*numpy.py' if it has the "
1004-
rb"same name as a library you intended to import\)\s+\Z"
1004+
rb"same name as a library you intended to import\)\s+\z"
10051005
)
10061006

10071007
popen = script_helper.spawn_python(os.path.join(tmp, "numpy.py"))
@@ -1022,14 +1022,14 @@ def test_script_maybe_not_shadowing_third_party(self):
10221022
f.write("this_script_does_not_attempt_to_import_numpy = True")
10231023

10241024
expected_error = (
1025-
rb"AttributeError: module 'numpy' has no attribute 'attr'\s+\Z"
1025+
rb"AttributeError: module 'numpy' has no attribute 'attr'\s+\z"
10261026
)
10271027
popen = script_helper.spawn_python('-c', 'import numpy; numpy.attr', cwd=tmp)
10281028
stdout, stderr = popen.communicate()
10291029
self.assertRegex(stdout, expected_error)
10301030

10311031
expected_error = (
1032-
rb"ImportError: cannot import name 'attr' from 'numpy' \(.*\)\s+\Z"
1032+
rb"ImportError: cannot import name 'attr' from 'numpy' \(.*\)\s+\z"
10331033
)
10341034
popen = script_helper.spawn_python('-c', 'from numpy import attr', cwd=tmp)
10351035
stdout, stderr = popen.communicate()

Lib/test/test_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6740,7 +6740,7 @@ def test_compute_files_to_delete_same_filename_different_extensions(self):
67406740
rotator = rotators[i]
67416741
candidates = rotator.getFilesToDelete()
67426742
self.assertEqual(len(candidates), n_files - backupCount, candidates)
6743-
matcher = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\Z")
6743+
matcher = re.compile(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\z")
67446744
for c in candidates:
67456745
d, fn = os.path.split(c)
67466746
self.assertStartsWith(fn, prefix+'.')

Lib/test/test_strtod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
(?P<int>\d*) # having a (possibly empty) integer part
2020
(?:\.(?P<frac>\d*))? # followed by an optional fractional part
2121
(?:E(?P<exp>[-+]?\d+))? # and an optional exponent
22-
\Z
22+
\z
2323
""", re.VERBOSE | re.IGNORECASE).match
2424

2525
# Pure Python version of correctly rounded string->float conversion.

0 commit comments

Comments
 (0)