gh-133306: Use \z instead of \Z in regular expressions in the stdlib … · python/cpython@84a08f8

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

Original file line numberDiff line numberDiff line change@@ -371,7 +371,7 @@ def _setoption(arg):

371371ifmessage:

372372message=re.escape(message)

373373ifmodule:

374-module=re.escape(module) +r'\Z'

374+module=re.escape(module) +r'\z'

375375iflineno:

376376try:

377377lineno=int(lineno)

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

6101610161026102_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)

6129612961306130delre

Original file line numberDiff line numberDiff line change@@ -30,7 +30,7 @@

30303131NLCRE=re.compile(r'\r\n|\r|\n')

3232NLCRE_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')

3434NLCRE_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 ":".

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)

69697070Original file line numberDiff line numberDiff line change@@ -1350,7 +1350,7 @@ def recall(self, s, event):

13501350self.text.see("insert")

13511351self.text.undo_block_stop()

135213521353-_last_newline_re=re.compile(r"[ \t]*(\n[ \t]*)?\Z")

1353+_last_newline_re=re.compile(r"[ \t]*(\n[ \t]*)?\z")

13541354defrunit(self):

13551355index_before=self.text.index("end-2c")

13561356line=self.text.get("iomark", "end-1c")

Original file line numberDiff line numberDiff line change@@ -14,7 +14,7 @@

1414r'(, value:\d)?'

1515r'(, waiters:\d+)?'

1616r'(, waiters:\d+\/\d+)?'# barrier

17-r')\]>\Z'

17+r')\]>\z'

1818)

1919RGX_REPR=re.compile(STR_RGX_REPR)

2020Original file line numberDiff line numberDiff line change@@ -300,7 +300,7 @@ def func():

300300# We're mostly just checking that this doesn't crash.

301301rc, stdout, stderr=assert_python_ok("-c", code)

302302self.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""")

304304self.assertFalse(stderr)

305305306306@refcount_test

Original file line numberDiff line numberDiff line change@@ -1001,7 +1001,7 @@ def test_script_shadowing_third_party(self):

1001100110021002expected_error=error+ (

10031003rb" \(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 )

1006100610071007popen=script_helper.spawn_python(os.path.join(tmp, "numpy.py"))

@@ -1022,14 +1022,14 @@ def test_script_maybe_not_shadowing_third_party(self):

10221022f.write("this_script_does_not_attempt_to_import_numpy = True")

1023102310241024expected_error= (

1025-rb"AttributeError: module 'numpy' has no attribute 'attr'\s+\Z"

1025+rb"AttributeError: module 'numpy' has no attribute 'attr'\s+\z"

10261026 )

10271027popen=script_helper.spawn_python('-c', 'import numpy; numpy.attr', cwd=tmp)

10281028stdout, stderr=popen.communicate()

10291029self.assertRegex(stdout, expected_error)

1030103010311031expected_error= (

1032-rb"ImportError: cannot import name 'attr' from 'numpy' \(.*\)\s+\Z"

1032+rb"ImportError: cannot import name 'attr' from 'numpy' \(.*\)\s+\z"

10331033 )

10341034popen=script_helper.spawn_python('-c', 'from numpy import attr', cwd=tmp)

10351035stdout, stderr=popen.communicate()

Original file line numberDiff line numberDiff line change@@ -6740,7 +6740,7 @@ def test_compute_files_to_delete_same_filename_different_extensions(self):

67406740rotator=rotators[i]

67416741candidates=rotator.getFilesToDelete()

67426742self.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")

67446744forcincandidates:

67456745d, fn=os.path.split(c)

67466746self.assertStartsWith(fn, prefix+'.')

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

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