On Sun, Dec 15, 2019 at 11:07 PM Serhiy Storchaka <storch...@gmail.com> wrote: > > I propose several changes: > > 1. Forbids calling str() without object if encoding or errors are > specified. It is very unlikely that this can break a real code, so I > propose to make it an error without a deprecation period. > > 2. Make the first parameter of str(), bytes() and bytearray() > positional-only. Originally this feature was an implementation artifact: > before 3.6 parameters of a C implemented function should be either all > positional-only (if used PyArg_ParseTuple), or all keyword (if used > PyArg_ParseTupleAndKeywords). So str(), bytes() and bytearray() accepted > the first parameter by keyword. We already made similar changes for > int(), float(), etc: int(x=42) no longer works. > > Unlikely str(object=object) is used in a real code, so we can skip a > deprecation period for this change too. >
+1 for 1 and 2. > 3. Make encoding required if errors is specified in str(). This will > reduce the number of possible combinations, makes str() more similar to > bytes() and bytearray() and simplify the mental model: if encoding is > specified, then we decode, and the first argument must be a bytes-like > object, otherwise we convert an object to a string using __str__. -0. We can omit `encoding="utf-8"` in bytes.decode() because the default encoding is always UTF-8. >>> x = "おはよう".encode() >>> x.decode(errors="strict") 'おはよう' So allowing `bytes(o, errors="replace")` instead of making encoding mandatory also makes sense to me. Regards, -- Inada Naoki <songofaca...@gmail.com> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/MDOU2IZ5YTCRS7VMR6DPHSQGSKGKDBFZ/ Code of Conduct: http://python.org/psf/codeofconduct/