File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,7 @@ def register(thecallable):
204204 function , _ = _getfunc (thecallable )
205205 params = inspect .signature (function ).parameters
206206 allparamnames = [p .name for p in params .values ()]
207- if not all (name in signature for name in allparamnames ): # pragma: no cover
207+ if not all (name in signature for name in allparamnames ):
208208 failures = [name for name in allparamnames if name not in signature ]
209209 wrapped = ["'{}'" .format (x ) for x in failures ]
210210 plural = "s" if len (failures ) > 1 else ""
@@ -222,7 +222,7 @@ def register(thecallable):
222222 dispatcher = _dispatcher_registry [fullname ]
223223 if hasattr (dispatcher , "_register" ): # co-operation with @typed, below
224224 return dispatcher ._register (f )
225- raise TypeError ("@typed: cannot register additional methods." ) # pragma: no cover
225+ raise TypeError ("@typed: cannot register additional methods." )
226226
227227
228228def typed (f ):
Original file line number Diff line number Diff line change @@ -100,6 +100,20 @@ def runtests():
100100 test [jack ("foo" ) == "foo" ]
101101 test_raises [TypeError , jack (3.14 )] # jack only accepts int or str
102102
103+ with testset ("error cases" ):
104+ with test_raises (TypeError , "@typed should only accept a single method" ):
105+ @typed
106+ def errorcase1 (x : int ):
107+ pass # pragma: no cover
108+ @typed # noqa: F811
109+ def errorcase1 (x : str ):
110+ pass # pragma: no cover
111+
112+ with test_raises (TypeError , "@generic should complain about missing type annotations" ):
113+ @generic
114+ def errorcase2 (x ):
115+ pass # pragma: no cover
116+
103117 with testset ("@typed integration with curry" ):
104118 f = curry (blubnify , 2 )
105119 test [callable (f )]
You can’t perform that action at this time.
0 commit comments