Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-15999: Accept arbitrary values for boolean parameters. #15609

Merged
merged 10 commits into from
Dec 3, 2022
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Other Language Changes
:meth:`~object.__index__` method).
(Contributed by Serhiy Storchaka in :issue:`37999`.)

* All builtin and extension functions and methods now accept arguments of any
type instead of just :class:`bool` and :class:`int` for boolean parameters.
(Contributed by Serhiy Storchaka in :issue:`15999`.)


New Modules
===========
Expand Down
4 changes: 0 additions & 4 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,6 @@ def test_cycle_setstate(self):
c.__setstate__((tuple('defg'), 0))
take(20, c)

# The second argument in the setstate tuple must be an int
with self.assertRaises(TypeError):
cycle('defg').__setstate__((list('abcdefg'), 'x'))

self.assertRaises(TypeError, cycle('').__setstate__, ())
self.assertRaises(TypeError, cycle('').__setstate__, ([],))

Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,12 +1629,6 @@ def test_resetids(self):
)
support.wait_process(pid, exitcode=0)

def test_resetids_wrong_type(self):
with self.assertRaises(TypeError):
self.spawn_func(sys.executable,
[sys.executable, "-c", "pass"],
os.environ, resetids=None)

def test_setpgroup(self):
pid = self.spawn_func(
sys.executable,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
All built-in functions now accept arguments of any type instead of just
``bool`` and ``int`` for boolean parameters.
52 changes: 26 additions & 26 deletions Modules/_codecsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ _codecs_escape_encode_impl(PyObject *module, PyObject *data,
_codecs.utf_7_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=0cd3a944a32a4089 input=22c395d357815d26]*/
/*[clinic end generated code: output=0cd3a944a32a4089 input=dbf8c8998102dc7d]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len,
Expand All @@ -273,14 +273,14 @@ _codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_8_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=10f74dec8d9bb8bf input=f611b3867352ba59]*/
/*[clinic end generated code: output=10f74dec8d9bb8bf input=ca06bc8a9c970e25]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len,
Expand All @@ -293,14 +293,14 @@ _codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_16_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=783b442abcbcc2d0 input=191d360bd7309180]*/
/*[clinic end generated code: output=783b442abcbcc2d0 input=5b0f52071ba6cadc]*/
{
int byteorder = 0;
/* This is overwritten unless final is true. */
Expand All @@ -315,14 +315,14 @@ _codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_16_le_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=899b9e6364379dcd input=c6904fdc27fb4724]*/
/*[clinic end generated code: output=899b9e6364379dcd input=115bd8c7b783d0bf]*/
{
int byteorder = -1;
/* This is overwritten unless final is true. */
Expand All @@ -337,14 +337,14 @@ _codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_16_be_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=49f6465ea07669c8 input=e49012400974649b]*/
/*[clinic end generated code: output=49f6465ea07669c8 input=63131422b01f9cb4]*/
{
int byteorder = 1;
/* This is overwritten unless final is true. */
Expand All @@ -367,14 +367,14 @@ _codecs.utf_16_ex_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
byteorder: int = 0
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int byteorder, int final)
/*[clinic end generated code: output=0f385f251ecc1988 input=5a9c19f2e6b6cf0e]*/
/*[clinic end generated code: output=0f385f251ecc1988 input=f368a51cf384bf4c]*/
{
/* This is overwritten unless final is true. */
Py_ssize_t consumed = data->len;
Expand All @@ -391,14 +391,14 @@ _codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_32_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=2fc961807f7b145f input=fd7193965627eb58]*/
/*[clinic end generated code: output=2fc961807f7b145f input=fcdf3658c5e9b5f3]*/
{
int byteorder = 0;
/* This is overwritten unless final is true. */
Expand All @@ -413,14 +413,14 @@ _codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_32_le_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=ec8f46b67a94f3e6 input=9078ec70acfe7613]*/
/*[clinic end generated code: output=ec8f46b67a94f3e6 input=12220556e885f817]*/
{
int byteorder = -1;
/* This is overwritten unless final is true. */
Expand All @@ -435,14 +435,14 @@ _codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
_codecs.utf_32_be_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=ff82bae862c92c4e input=f1ae1bbbb86648ff]*/
/*[clinic end generated code: output=ff82bae862c92c4e input=2bc669b4781598db]*/
{
int byteorder = 1;
/* This is overwritten unless final is true. */
Expand All @@ -465,14 +465,14 @@ _codecs.utf_32_ex_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
byteorder: int = 0
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int byteorder, int final)
/*[clinic end generated code: output=6bfb177dceaf4848 input=e46a73bc859d0bd0]*/
/*[clinic end generated code: output=6bfb177dceaf4848 input=4a2323d0013620df]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
Expand Down Expand Up @@ -577,14 +577,14 @@ _codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
_codecs.mbcs_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=39b65b8598938c4b input=1c1d50f08fa53789]*/
/*[clinic end generated code: output=39b65b8598938c4b input=f144ad1ed6d8f5a6]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len,
Expand All @@ -596,14 +596,14 @@ _codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
_codecs.oem_decode
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
const char *errors, int final)
/*[clinic end generated code: output=da1617612f3fcad8 input=81b67cba811022e5]*/
/*[clinic end generated code: output=da1617612f3fcad8 input=629bf87376d211b4]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeCodePageStateful(CP_OEMCP,
Expand All @@ -616,14 +616,14 @@ _codecs.code_page_decode
codepage: int
data: Py_buffer
errors: str(accept={str, NoneType}) = None
final: bool(accept={int}) = False
final: bool = False
/
[clinic start generated code]*/

static PyObject *
_codecs_code_page_decode_impl(PyObject *module, int codepage,
Py_buffer *data, const char *errors, int final)
/*[clinic end generated code: output=53008ea967da3fff input=c5f58d036cb63575]*/
/*[clinic end generated code: output=53008ea967da3fff input=6a32589b0658c277]*/
{
Py_ssize_t consumed = data->len;
PyObject *decoded = PyUnicode_DecodeCodePageStateful(codepage,
Expand Down
Loading