@@ -544,13 +544,18 @@ def test_double_invert_folded(source, expected):
544544 ('-5 + True' , '-4' ),
545545 ('10 * False' , '0' ),
546546 ('True + True' , '2' ),
547+ ('~True' , '-2' ),
548+ ('~False' , '-1' )
547549 ]
548550)
549551def test_mixed_numeric_bool_folded (source , expected ):
550552 """
551553 Test folding of expressions mixing numeric and boolean operands.
552554
553555 Python treats True as 1 and False as 0 in numeric contexts.
556+
557+ ~ on a bool is deprecated from python 3.12, so it is folded by computing the
558+ value directly rather than evaluating it (which would emit a DeprecationWarning).
554559 """
555560 if sys .version_info < (3 , 4 ):
556561 pytest .skip ('NameConstant not in python < 3.4' )
@@ -562,16 +567,18 @@ def test_mixed_numeric_bool_folded(source, expected):
562567 ('source' , 'expected' ), [
563568 ('~True' , '~True' ),
564569 ('~False' , '~False' ),
570+ ('~~False' , '~~False' ),
565571 ]
566572)
567- def test_invert_bool_not_folded (source , expected ):
573+ def test_invert_bool_not_folded_from_316 (source , expected , monkeypatch ):
568574 """
569- ~ on a bool is deprecated from python 3.12, so it is not folded (evaluating
570- it would emit a DeprecationWarning, and the saving is negligible) .
575+ ~ on a bool is removed in python 3.16, where it raises.
576+ The minified code should fail the same way the original would .
571577 """
572578 if sys .version_info < (3 , 4 ):
573579 pytest .skip ('NameConstant not in python < 3.4' )
574580
581+ monkeypatch .setattr (sys , 'version_info' , (3 , 16 , 0 ))
575582 run_test (source , expected )
576583
577584
0 commit comments