File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 3
3
- All parameters on ` NewType.__call__ ` are now positional-only. This means that
4
4
the signature of ` typing_extensions.NewType.__call__ ` now exactly matches the
5
5
signature of ` typing.NewType.__call__ ` . Patch by Alex Waygood.
6
+ - ` typing.deprecated ` now gives a better error message if you pass a non-` str `
7
+ argument to the ` msg ` parameter. Patch by Alex Waygood.
6
8
7
9
# Release 4.8.0 (September 17, 2023)
8
10
Original file line number Diff line number Diff line change @@ -480,6 +480,21 @@ def d():
480
480
warnings .simplefilter ("error" )
481
481
d ()
482
482
483
+ def test_only_strings_allowed (self ):
484
+ with self .assertRaisesRegex (
485
+ TypeError ,
486
+ "Expected an object of type str for 'msg', not 'type'"
487
+ ):
488
+ @deprecated
489
+ class Foo : ...
490
+
491
+ with self .assertRaisesRegex (
492
+ TypeError ,
493
+ "Expected an object of type str for 'msg', not 'function'"
494
+ ):
495
+ @deprecated
496
+ def foo (): ...
497
+
483
498
484
499
class AnyTests (BaseTestCase ):
485
500
def test_can_subclass (self ):
Original file line number Diff line number Diff line change @@ -2331,6 +2331,11 @@ def g(x: str) -> int: ...
2331
2331
See PEP 702 for details.
2332
2332
2333
2333
"""
2334
+ if not isinstance (msg , str ):
2335
+ raise TypeError (
2336
+ f"Expected an object of type str for 'msg', not { type (msg ).__name__ !r} "
2337
+ )
2338
+
2334
2339
def decorator (arg : _T , / ) -> _T :
2335
2340
if category is None :
2336
2341
arg .__deprecated__ = msg
You can’t perform that action at this time.
0 commit comments