Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10db28b

Browse filesBrowse files
miss-islingtonbelm0blurb-it[bot]
authored
[3.11] gh-104018: disallow "z" format specifier in %-format of byte strings (GH-104033) (#104058)
gh-104018: disallow "z" format specifier in %-format of byte strings (GH-104033) PEP-0682 specified that %-formatting would not support the "z" specifier, but it was unintentionally allowed for bytes. This PR makes use of the "z" flag an error for %-formatting in a bytestring. Issue: GH-104018 --------- (cherry picked from commit 3ed8c88) Co-authored-by: John Belmonte <john@neggie.net> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 723aacb commit 10db28b
Copy full SHA for 10db28b

File tree

Expand file treeCollapse file tree

3 files changed

+3
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+3
-1
lines changed

‎Lib/test/test_format.py

Copy file name to clipboardExpand all lines: Lib/test/test_format.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ def test_specifier_z_error(self):
619619
error_msg = re.escape("unsupported format character 'z'")
620620
with self.assertRaisesRegex(ValueError, error_msg):
621621
"%z.1f" % 0 # not allowed in old style string interpolation
622+
with self.assertRaisesRegex(ValueError, error_msg):
623+
b"%z.1f" % 0
622624

623625

624626
if __name__ == "__main__":
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disallow the "z" format specifier in %-format of bytes objects.

‎Objects/bytesobject.c

Copy file name to clipboardExpand all lines: Objects/bytesobject.c
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
714714
case ' ': flags |= F_BLANK; continue;
715715
case '#': flags |= F_ALT; continue;
716716
case '0': flags |= F_ZERO; continue;
717-
case 'z': flags |= F_NO_NEG_0; continue;
718717
}
719718
break;
720719
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.