Skip to content

Commit f697407

Browse files
committed
pythongh-104018: disallow "z" format specifier in %-format of byte strings
PEP-0682 specified that %-formatting would not support the "z" specifier, but it was unintentionally allowed for a byte strings. Issue: python#104018
1 parent 69bc86c commit f697407

File tree

2 files changed

+2
-1
lines changed

2 files changed

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

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)