Skip to content

Commit 84a08f8

Browse files
gh-133306: Use \z instead of \Z in regular expressions in the stdlib (GH-133337)
1 parent add0ca9 commit 84a08f8

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.

Lib/test/test_tkinter/widget_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def checkInvalidParam(self, widget, name, value, errmsg=None):
6565
orig = widget[name]
6666
if errmsg is not None:
6767
errmsg = errmsg.format(re.escape(str(value)))
68-
errmsg = fr'\A{errmsg}\Z'
68+
errmsg = fr'\A{errmsg}\z'
6969
with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
7070
widget[name] = value
7171
self.assertEqual(widget[name], orig)

Lib/test/test_ttk/test_widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def _show_drop_down_listbox(self):
490490
width = self.combo.winfo_width()
491491
x, y = width - 5, 5
492492
if sys.platform != 'darwin': # there's no down arrow on macOS
493-
self.assertRegex(self.combo.identify(x, y), r'.*downarrow\Z')
493+
self.assertRegex(self.combo.identify(x, y), r'.*downarrow\z')
494494
self.combo.event_generate('<Button-1>', x=x, y=y)
495495
self.combo.event_generate('<ButtonRelease-1>', x=x, y=y)
496496

@@ -1250,7 +1250,7 @@ def _click_increment_arrow(self):
12501250
height = self.spin.winfo_height()
12511251
x = width - 5
12521252
y = height//2 - 5
1253-
self.assertRegex(self.spin.identify(x, y), r'.*uparrow\Z')
1253+
self.assertRegex(self.spin.identify(x, y), r'.*uparrow\z')
12541254
self.spin.event_generate('<ButtonPress-1>', x=x, y=y)
12551255
self.spin.event_generate('<ButtonRelease-1>', x=x, y=y)
12561256
self.spin.update_idletasks()
@@ -1260,7 +1260,7 @@ def _click_decrement_arrow(self):
12601260
height = self.spin.winfo_height()
12611261
x = width - 5
12621262
y = height//2 + 4
1263-
self.assertRegex(self.spin.identify(x, y), r'.*downarrow\Z')
1263+
self.assertRegex(self.spin.identify(x, y), r'.*downarrow\z')
12641264
self.spin.event_generate('<ButtonPress-1>', x=x, y=y)
12651265
self.spin.event_generate('<ButtonRelease-1>', x=x, y=y)
12661266
self.spin.update_idletasks()

Lib/textwrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TextWrapper:
8686
-(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
8787
(?= %(lt)s -? %(lt)s)
8888
| # end of word
89-
(?=%(ws)s|\Z)
89+
(?=%(ws)s|\z)
9090
| # em-dash
9191
(?<=%(wp)s) (?=-{2,}\w)
9292
)
@@ -107,7 +107,7 @@ class TextWrapper:
107107
sentence_end_re = re.compile(r'[a-z]' # lowercase letter
108108
r'[\.\!\?]' # sentence-ending punct.
109109
r'[\"\']?' # optional end-of-quote
110-
r'\Z') # end of chunk
110+
r'\z') # end of chunk
111111

112112
def __init__(self,
113113
width=70,

Lib/tokenize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _compile(expr):
132132
group("'", r'\\\r?\n'),
133133
StringPrefix + r'"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
134134
group('"', r'\\\r?\n'))
135-
PseudoExtras = group(r'\\\r?\n|\Z', Comment, Triple)
135+
PseudoExtras = group(r'\\\r?\n|\z', Comment, Triple)
136136
PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
137137

138138
# For a given string prefix plus quotes, endpats maps it to a regex

Lib/urllib/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def _check_bracketed_netloc(netloc):
460460
# https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/
461461
def _check_bracketed_host(hostname):
462462
if hostname.startswith('v'):
463-
if not re.match(r"\Av[a-fA-F0-9]+\..+\Z", hostname):
463+
if not re.match(r"\Av[a-fA-F0-9]+\..+\z", hostname):
464464
raise ValueError(f"IPvFuture address is invalid")
465465
else:
466466
ip = ipaddress.ip_address(hostname) # Throws Value Error if not IPv6 or IPv4

Lib/zipfile/_path/glob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def extend(self, pattern):
3737
Apply '(?s:)' to create a non-matching group that
3838
matches newlines (valid on Unix).
3939
40-
Append '\Z' to imply fullmatch even when match is used.
40+
Append '\z' to imply fullmatch even when match is used.
4141
"""
42-
return rf'(?s:{pattern})\Z'
42+
return rf'(?s:{pattern})\z'
4343

4444
def match_dirs(self, pattern):
4545
"""

0 commit comments

Comments
 (0)