pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/a87c46eab3c306b1c5b8a072b7b30ac2c50651c0

9af82350aeda.css" /> bpo-15999: Accept arbitrary values for boolean parameters. (#15609) · python/cpython@a87c46e · GitHub
Skip to content

Commit a87c46e

Browse files
bpo-15999: Accept arbitrary values for boolean parameters. (#15609)
builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
1 parent c68573b commit a87c46e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+297
-302
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ Other Language Changes
178178
In a future Python version they will be eventually a :exc:`SyntaxError`.
179179
(Contributed by Victor Stinner in :gh:`98401`.)
180180

181+
* All builtin and extension callables expecting boolean parameters now accept
182+
arguments of any type instead of just :class:`bool` and :class:`int`.
183+
(Contributed by Serhiy Storchaka in :gh:`60203`.)
184+
181185

182186
New Modules
183187
===========

Lib/test/test_itertools.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,6 @@ def test_cycle_setstate(self):
739739
c.__setstate__((tuple('defg'), 0))
740740
take(20, c)
741741

742-
# The second argument in the setstate tuple must be an int
743-
with self.assertRaises(TypeError):
744-
cycle('defg').__setstate__((list('abcdefg'), 'x'))
745-
746742
self.assertRaises(TypeError, cycle('').__setstate__, ())
747743
self.assertRaises(TypeError, cycle('').__setstate__, ([],))
748744

Lib/test/test_posix.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,12 +1646,6 @@ def test_resetids(self):
16461646
)
16471647
support.wait_process(pid, exitcode=0)
16481648

1649-
def test_resetids_wrong_type(self):
1650-
with self.assertRaises(TypeError):
1651-
self.spawn_func(sys.executable,
1652-
[sys.executable, "-c", "pass"],
1653-
os.environ, resetids=None)
1654-
16551649
def test_setpgroup(self):
16561650
pid = self.spawn_func(
16571651
sys.executable,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
All built-in functions now accept arguments of any type instead of just
2+
``bool`` and ``int`` for boolean parameters.

Modules/_codecsmodule.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@ _codecs_escape_encode_impl(PyObject *module, PyObject *data,
256256
_codecs.utf_7_decode
257257
data: Py_buffer
258258
errors: str(accept={str, NoneType}) = None
259-
final: bool(accept={int}) = False
259+
final: bool = False
260260
/
261261
[clinic start generated code]*/
262262

263263
static PyObject *
264264
_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
265265
const char *errors, int final)
266-
/*[clinic end generated code: output=0cd3a944a32a4089 input=22c395d357815d26]*/
266+
/*[clinic end generated code: output=0cd3a944a32a4089 input=dbf8c8998102dc7d]*/
267267
{
268268
Py_ssize_t consumed = data->len;
269269
PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len,
@@ -276,14 +276,14 @@ _codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
276276
_codecs.utf_8_decode
277277
data: Py_buffer
278278
errors: str(accept={str, NoneType}) = None
279-
final: bool(accept={int}) = False
279+
final: bool = False
280280
/
281281
[clinic start generated code]*/
282282

283283
static PyObject *
284284
_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
285285
const char *errors, int final)
286-
/*[clinic end generated code: output=10f74dec8d9bb8bf input=f611b3867352ba59]*/
286+
/*[clinic end generated code: output=10f74dec8d9bb8bf input=ca06bc8a9c970e25]*/
287287
{
288288
Py_ssize_t consumed = data->len;
289289
PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len,
@@ -296,14 +296,14 @@ _codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
296296
_codecs.utf_16_decode
297297
data: Py_buffer
298298
errors: str(accept={str, NoneType}) = None
299-
final: bool(accept={int}) = False
299+
final: bool = False
300300
/
301301
[clinic start generated code]*/
302302

303303
static PyObject *
304304
_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
305305
const char *errors, int final)
306-
/*[clinic end generated code: output=783b442abcbcc2d0 input=191d360bd7309180]*/
306+
/*[clinic end generated code: output=783b442abcbcc2d0 input=5b0f52071ba6cadc]*/
307307
{
308308
int byteorder = 0;
309309
/* This is overwritten unless final is true. */
@@ -318,14 +318,14 @@ _codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
318318
_codecs.utf_16_le_decode
319319
data: Py_buffer
320320
errors: str(accept={str, NoneType}) = None
321-
final: bool(accept={int}) = False
321+
final: bool = False
322322
/
323323
[clinic start generated code]*/
324324

325325
static PyObject *
326326
_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
327327
const char *errors, int final)
328-
/*[clinic end generated code: output=899b9e6364379dcd input=c6904fdc27fb4724]*/
328+
/*[clinic end generated code: output=899b9e6364379dcd input=115bd8c7b783d0bf]*/
329329
{
330330
int byteorder = -1;
331331
/* This is overwritten unless final is true. */
@@ -340,14 +340,14 @@ _codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
340340
_codecs.utf_16_be_decode
341341
data: Py_buffer
342342
errors: str(accept={str, NoneType}) = None
343-
final: bool(accept={int}) = False
343+
final: bool = False
344344
/
345345
[clinic start generated code]*/
346346

347347
static PyObject *
348348
_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
349349
const char *errors, int final)
350-
/*[clinic end generated code: output=49f6465ea07669c8 input=e49012400974649b]*/
350+
/*[clinic end generated code: output=49f6465ea07669c8 input=63131422b01f9cb4]*/
351351
{
352352
int byteorder = 1;
353353
/* This is overwritten unless final is true. */
@@ -370,14 +370,14 @@ _codecs.utf_16_ex_decode
370370
data: Py_buffer
371371
errors: str(accept={str, NoneType}) = None
372372
byteorder: int = 0
373-
final: bool(accept={int}) = False
373+
final: bool = False
374374
/
375375
[clinic start generated code]*/
376376

377377
static PyObject *
378378
_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
379379
const char *errors, int byteorder, int final)
380-
/*[clinic end generated code: output=0f385f251ecc1988 input=5a9c19f2e6b6cf0e]*/
380+
/*[clinic end generated code: output=0f385f251ecc1988 input=f368a51cf384bf4c]*/
381381
{
382382
/* This is overwritten unless final is true. */
383383
Py_ssize_t consumed = data->len;
@@ -394,14 +394,14 @@ _codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
394394
_codecs.utf_32_decode
395395
data: Py_buffer
396396
errors: str(accept={str, NoneType}) = None
397-
final: bool(accept={int}) = False
397+
final: bool = False
398398
/
399399
[clinic start generated code]*/
400400

401401
static PyObject *
402402
_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
403403
const char *errors, int final)
404-
/*[clinic end generated code: output=2fc961807f7b145f input=fd7193965627eb58]*/
404+
/*[clinic end generated code: output=2fc961807f7b145f input=fcdf3658c5e9b5f3]*/
405405
{
406406
int byteorder = 0;
407407
/* This is overwritten unless final is true. */
@@ -416,14 +416,14 @@ _codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
416416
_codecs.utf_32_le_decode
417417
data: Py_buffer
418418
errors: str(accept={str, NoneType}) = None
419-
final: bool(accept={int}) = False
419+
final: bool = False
420420
/
421421
[clinic start generated code]*/
422422

423423
static PyObject *
424424
_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
425425
const char *errors, int final)
426-
/*[clinic end generated code: output=ec8f46b67a94f3e6 input=9078ec70acfe7613]*/
426+
/*[clinic end generated code: output=ec8f46b67a94f3e6 input=12220556e885f817]*/
427427
{
428428
int byteorder = -1;
429429
/* This is overwritten unless final is true. */
@@ -438,14 +438,14 @@ _codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
438438
_codecs.utf_32_be_decode
439439
data: Py_buffer
440440
errors: str(accept={str, NoneType}) = None
441-
final: bool(accept={int}) = False
441+
final: bool = False
442442
/
443443
[clinic start generated code]*/
444444

445445
static PyObject *
446446
_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
447447
const char *errors, int final)
448-
/*[clinic end generated code: output=ff82bae862c92c4e input=f1ae1bbbb86648ff]*/
448+
/*[clinic end generated code: output=ff82bae862c92c4e input=2bc669b4781598db]*/
449449
{
450450
int byteorder = 1;
451451
/* This is overwritten unless final is true. */
@@ -468,14 +468,14 @@ _codecs.utf_32_ex_decode
468468
data: Py_buffer
469469
errors: str(accept={str, NoneType}) = None
470470
byteorder: int = 0
471-
final: bool(accept={int}) = False
471+
final: bool = False
472472
/
473473
[clinic start generated code]*/
474474

475475
static PyObject *
476476
_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
477477
const char *errors, int byteorder, int final)
478-
/*[clinic end generated code: output=6bfb177dceaf4848 input=e46a73bc859d0bd0]*/
478+
/*[clinic end generated code: output=6bfb177dceaf4848 input=4a2323d0013620df]*/
479479
{
480480
Py_ssize_t consumed = data->len;
481481
PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
@@ -490,14 +490,14 @@ _codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
490490
_codecs.unicode_escape_decode
491491
data: Py_buffer(accept={str, buffer})
492492
errors: str(accept={str, NoneType}) = None
493-
final: bool(accept={int}) = True
493+
final: bool = True
494494
/
495495
[clinic start generated code]*/
496496

497497
static PyObject *
498498
_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
499499
const char *errors, int final)
500-
/*[clinic end generated code: output=b284f97b12c635ee input=6154f039a9f7c639]*/
500+
/*[clinic end generated code: output=b284f97b12c635ee input=15019f081ffe272b]*/
501501
{
502502
Py_ssize_t consumed = data->len;
503503
PyObject *decoded = _PyUnicode_DecodeUnicodeEscapeStateful(data->buf, data->len,
@@ -510,14 +510,14 @@ _codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
510510
_codecs.raw_unicode_escape_decode
511511
data: Py_buffer(accept={str, buffer})
512512
errors: str(accept={str, NoneType}) = None
513-
final: bool(accept={int}) = True
513+
final: bool = True
514514
/
515515
[clinic start generated code]*/
516516

517517
static PyObject *
518518
_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
519519
const char *errors, int final)
520-
/*[clinic end generated code: output=11dbd96301e2879e input=2d166191beb3235a]*/
520+
/*[clinic end generated code: output=11dbd96301e2879e input=b93f823aa8c343ad]*/
521521
{
522522
Py_ssize_t consumed = data->len;
523523
PyObject *decoded = _PyUnicode_DecodeRawUnicodeEscapeStateful(data->buf, data->len,
@@ -586,14 +586,14 @@ _codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
586586
_codecs.mbcs_decode
587587
data: Py_buffer
588588
errors: str(accept={str, NoneType}) = None
589-
final: bool(accept={int}) = False
589+
final: bool = False
590590
/
591591
[clinic start generated code]*/
592592

593593
static PyObject *
594594
_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
595595
const char *errors, int final)
596-
/*[clinic end generated code: output=39b65b8598938c4b input=1c1d50f08fa53789]*/
596+
/*[clinic end generated code: output=39b65b8598938c4b input=f144ad1ed6d8f5a6]*/
597597
{
598598
Py_ssize_t consumed = data->len;
599599
PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len,
@@ -605,14 +605,14 @@ _codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
605605
_codecs.oem_decode
606606
data: Py_buffer
607607
errors: str(accept={str, NoneType}) = None
608-
final: bool(accept={int}) = False
608+
final: bool = False
609609
/
610610
[clinic start generated code]*/
611611

612612
static PyObject *
613613
_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
614614
const char *errors, int final)
615-
/*[clinic end generated code: output=da1617612f3fcad8 input=81b67cba811022e5]*/
615+
/*[clinic end generated code: output=da1617612f3fcad8 input=629bf87376d211b4]*/
616616
{
617617
Py_ssize_t consumed = data->len;
618618
PyObject *decoded = PyUnicode_DecodeCodePageStateful(CP_OEMCP,
@@ -625,14 +625,14 @@ _codecs.code_page_decode
625625
codepage: int
626626
data: Py_buffer
627627
errors: str(accept={str, NoneType}) = None
628-
final: bool(accept={int}) = False
628+
final: bool = False
629629
/
630630
[clinic start generated code]*/
631631

632632
static PyObject *
633633
_codecs_code_page_decode_impl(PyObject *module, int codepage,
634634
Py_buffer *data, const char *errors, int final)
635-
/*[clinic end generated code: output=53008ea967da3fff input=c5f58d036cb63575]*/
635+
/*[clinic end generated code: output=53008ea967da3fff input=6a32589b0658c277]*/
636636
{
637637
Py_ssize_t consumed = data->len;
638638
PyObject *decoded = PyUnicode_DecodeCodePageStateful(codepage,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy