Skip to content

Commit 3ed8c88

Browse files
belm0blurb-it[bot]
andauthored
pythongh-104018: disallow "z" format specifier in %-format of byte strings (pythonGH-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: python#104018 --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 5078eed commit 3ed8c88

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

Lib/test/test_format.py

+2
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__":
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

-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,6 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
705705
case ' ': flags |= F_BLANK; continue;
706706
case '#': flags |= F_ALT; continue;
707707
case '0': flags |= F_ZERO; continue;
708-
case 'z': flags |= F_NO_NEG_0; continue;
709708
}
710709
break;
711710
}

0 commit comments

Comments
 (0)