Skip to content

Commit

Permalink
pythongh-104018: disallow "z" format specifier in %-format of byte st…
Browse files Browse the repository at this point in the history
…rings

PEP-0682 specified that %-formatting would not support the "z"
specifier, but it was unintentionally allowed for a byte strings.

Issue: python#104018
  • Loading branch information
belm0 committed May 1, 2023
1 parent 69bc86c commit f697407
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ def test_specifier_z_error(self):
error_msg = re.escape("unsupported format character 'z'")
with self.assertRaisesRegex(ValueError, error_msg):
"%z.1f" % 0 # not allowed in old style string interpolation
with self.assertRaisesRegex(ValueError, error_msg):
b"%z.1f" % 0


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
case ' ': flags |= F_BLANK; continue;
case '#': flags |= F_ALT; continue;
case '0': flags |= F_ZERO; continue;
case 'z': flags |= F_NO_NEG_0; continue;
}
break;
}
Expand Down

0 comments on commit f697407

Please sign in to comment.