@@ -1751,7 +1751,7 @@ def test_depr_star_must_come_before_star(self):
1751
1751
* [from 3.14]
1752
1752
Docstring.
1753
1753
"""
1754
- err = "Function 'bar': '* [from ...]' must come before '*'"
1754
+ err = "Function 'bar': '* [from ...]' must precede '*'"
1755
1755
self .expect_failure (block , err , lineno = 4 )
1756
1756
1757
1757
def test_depr_star_duplicate (self ):
@@ -1765,7 +1765,7 @@ def test_depr_star_duplicate(self):
1765
1765
c: int
1766
1766
Docstring.
1767
1767
"""
1768
- err = "Function 'bar' uses '* [from ... ]' more than once."
1768
+ err = "Function 'bar' uses '* [from 3.14 ]' more than once."
1769
1769
self .expect_failure (block , err , lineno = 5 )
1770
1770
1771
1771
def test_depr_star_duplicate2 (self ):
@@ -1779,7 +1779,7 @@ def test_depr_star_duplicate2(self):
1779
1779
c: int
1780
1780
Docstring.
1781
1781
"""
1782
- err = "Function 'bar' uses '* [from ... ]' more than once. "
1782
+ err = "Function 'bar': '* [from 3.15 ]' must precede '* [from 3.14]' "
1783
1783
self .expect_failure (block , err , lineno = 5 )
1784
1784
1785
1785
def test_depr_slash_duplicate (self ):
@@ -1793,21 +1793,21 @@ def test_depr_slash_duplicate(self):
1793
1793
c: int
1794
1794
Docstring.
1795
1795
"""
1796
- err = "Function 'bar' uses '/ [from ... ]' more than once."
1796
+ err = "Function 'bar' uses '/ [from 3.14 ]' more than once."
1797
1797
self .expect_failure (block , err , lineno = 5 )
1798
1798
1799
1799
def test_depr_slash_duplicate2 (self ):
1800
1800
block = """
1801
1801
module foo
1802
1802
foo.bar
1803
1803
a: int
1804
- / [from 3.14]
1805
- b: int
1806
1804
/ [from 3.15]
1805
+ b: int
1806
+ / [from 3.14]
1807
1807
c: int
1808
1808
Docstring.
1809
1809
"""
1810
- err = "Function 'bar' uses '/ [from ... ]' more than once. "
1810
+ err = "Function 'bar': '/ [from 3.14 ]' must precede '/ [from 3.15]' "
1811
1811
self .expect_failure (block , err , lineno = 5 )
1812
1812
1813
1813
def test_single_slash (self ):
@@ -2724,7 +2724,15 @@ class ClinicFunctionalTest(unittest.TestCase):
2724
2724
locals ().update ((name , getattr (ac_tester , name ))
2725
2725
for name in dir (ac_tester ) if name .startswith ('test_' ))
2726
2726
2727
- def check_depr_star (self , pnames , fn , * args , name = None , ** kwds ):
2727
+ def check_depr (self , regex , fn , / , * args , ** kwds ):
2728
+ with self .assertWarnsRegex (DeprecationWarning , regex ) as cm :
2729
+ # Record the line number, so we're sure we've got the correct stack
2730
+ # level on the deprecation warning.
2731
+ _ , lineno = fn (* args , ** kwds ), sys ._getframe ().f_lineno
2732
+ self .assertEqual (cm .filename , __file__ )
2733
+ self .assertEqual (cm .lineno , lineno )
2734
+
2735
+ def check_depr_star (self , pnames , fn , / , * args , name = None , ** kwds ):
2728
2736
if name is None :
2729
2737
name = fn .__qualname__
2730
2738
if isinstance (fn , type ):
@@ -2734,12 +2742,7 @@ def check_depr_star(self, pnames, fn, *args, name=None, **kwds):
2734
2742
fr"{ re .escape (name )} \(\) is deprecated. Parameters? { pnames } will "
2735
2743
fr"become( a)? keyword-only parameters? in Python 3\.14"
2736
2744
)
2737
- with self .assertWarnsRegex (DeprecationWarning , regex ) as cm :
2738
- # Record the line number, so we're sure we've got the correct stack
2739
- # level on the deprecation warning.
2740
- _ , lineno = fn (* args , ** kwds ), sys ._getframe ().f_lineno
2741
- self .assertEqual (cm .filename , __file__ )
2742
- self .assertEqual (cm .lineno , lineno )
2745
+ self .check_depr (regex , fn , * args , ** kwds )
2743
2746
2744
2747
def check_depr_kwd (self , pnames , fn , * args , name = None , ** kwds ):
2745
2748
if name is None :
@@ -2749,15 +2752,10 @@ def check_depr_kwd(self, pnames, fn, *args, name=None, **kwds):
2749
2752
pl = 's' if ' ' in pnames else ''
2750
2753
regex = (
2751
2754
fr"Passing keyword argument{ pl } { pnames } to "
2752
- fr"{ re .escape (name )} \(\) is deprecated. Corresponding parameter { pl } "
2755
+ fr"{ re .escape (name )} \(\) is deprecated. Parameter { pl } { pnames } "
2753
2756
fr"will become positional-only in Python 3\.14."
2754
2757
)
2755
- with self .assertWarnsRegex (DeprecationWarning , regex ) as cm :
2756
- # Record the line number, so we're sure we've got the correct stack
2757
- # level on the deprecation warning.
2758
- _ , lineno = fn (* args , ** kwds ), sys ._getframe ().f_lineno
2759
- self .assertEqual (cm .filename , __file__ )
2760
- self .assertEqual (cm .lineno , lineno )
2758
+ self .check_depr (regex , fn , * args , ** kwds )
2761
2759
2762
2760
def test_objects_converter (self ):
2763
2761
with self .assertRaises (TypeError ):
@@ -3368,6 +3366,24 @@ def test_depr_star_noinline(self):
3368
3366
check ("a" , "b" , c = "c" )
3369
3367
self .assertRaises (TypeError , fn , "a" , "b" , "c" , "d" )
3370
3368
3369
+ def test_depr_star_multi (self ):
3370
+ fn = ac_tester .depr_star_multi
3371
+ self .assertRaises (TypeError , fn , "a" )
3372
+ fn ("a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3373
+ errmsg = (
3374
+ "Passing more than 1 positional argument to depr_star_multi() is deprecated. "
3375
+ "Parameter 'b' will become a keyword-only parameter in Python 3.16. "
3376
+ "Parameters 'c' and 'd' will become keyword-only parameters in Python 3.15. "
3377
+ "Parameters 'e', 'f' and 'g' will become keyword-only parameters in Python 3.14." )
3378
+ check = partial (self .check_depr , re .escape (errmsg ), fn )
3379
+ check ("a" , "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3380
+ check ("a" , "b" , "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3381
+ check ("a" , "b" , "c" , "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3382
+ check ("a" , "b" , "c" , "d" , "e" , f = "f" , g = "g" , h = "h" )
3383
+ check ("a" , "b" , "c" , "d" , "e" , "f" , g = "g" , h = "h" )
3384
+ check ("a" , "b" , "c" , "d" , "e" , "f" , "g" , h = "h" )
3385
+ self .assertRaises (TypeError , fn , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" )
3386
+
3371
3387
def test_depr_kwd_required_1 (self ):
3372
3388
fn = ac_tester .depr_kwd_required_1
3373
3389
fn ("a" , "b" )
@@ -3452,6 +3468,44 @@ def test_depr_kwd_noinline(self):
3452
3468
self .assertRaises (TypeError , fn , "a" , c = "c" )
3453
3469
self .assertRaises (TypeError , fn , a = "a" , b = "b" , c = "c" )
3454
3470
3471
+ def test_depr_kwd_multi (self ):
3472
+ fn = ac_tester .depr_kwd_multi
3473
+ fn ("a" , "b" , "c" , "d" , "e" , "f" , "g" , h = "h" )
3474
+ errmsg = (
3475
+ "Passing keyword arguments 'b', 'c', 'd', 'e', 'f' and 'g' to depr_kwd_multi() is deprecated. "
3476
+ "Parameter 'b' will become positional-only in Python 3.14. "
3477
+ "Parameters 'c' and 'd' will become positional-only in Python 3.15. "
3478
+ "Parameters 'e', 'f' and 'g' will become positional-only in Python 3.16." )
3479
+ check = partial (self .check_depr , re .escape (errmsg ), fn )
3480
+ check ("a" , "b" , "c" , "d" , "e" , "f" , g = "g" , h = "h" )
3481
+ check ("a" , "b" , "c" , "d" , "e" , f = "f" , g = "g" , h = "h" )
3482
+ check ("a" , "b" , "c" , "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3483
+ check ("a" , "b" , "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3484
+ check ("a" , "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3485
+ check ("a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3486
+ self .assertRaises (TypeError , fn , a = "a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" , h = "h" )
3487
+
3488
+ def test_depr_multi (self ):
3489
+ fn = ac_tester .depr_multi
3490
+ self .assertRaises (TypeError , fn , "a" , "b" , "c" , "d" , "e" , "f" , "g" )
3491
+ errmsg = (
3492
+ "Passing more than 4 positional arguments to depr_multi() is deprecated. "
3493
+ "Parameter 'e' will become a keyword-only parameter in Python 3.15. "
3494
+ "Parameter 'f' will become a keyword-only parameter in Python 3.14." )
3495
+ check = partial (self .check_depr , re .escape (errmsg ), fn )
3496
+ check ("a" , "b" , "c" , "d" , "e" , "f" , g = "g" )
3497
+ check ("a" , "b" , "c" , "d" , "e" , f = "f" , g = "g" )
3498
+ fn ("a" , "b" , "c" , "d" , e = "e" , f = "f" , g = "g" )
3499
+ fn ("a" , "b" , "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3500
+ errmsg = (
3501
+ "Passing keyword arguments 'b' and 'c' to depr_multi() is deprecated. "
3502
+ "Parameter 'b' will become positional-only in Python 3.14. "
3503
+ "Parameter 'c' will become positional-only in Python 3.15." )
3504
+ check = partial (self .check_depr , re .escape (errmsg ), fn )
3505
+ check ("a" , "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3506
+ check ("a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3507
+ self .assertRaises (TypeError , fn , a = "a" , b = "b" , c = "c" , d = "d" , e = "e" , f = "f" , g = "g" )
3508
+
3455
3509
3456
3510
class PermutationTests (unittest .TestCase ):
3457
3511
"""Test permutation support functions."""
0 commit comments