2323
2424__all__ = ['base' ]
2525
26- from inspect import isclass
26+ from inspect import getargspec , isclass
2727
2828from decorator import decorator
2929from moretools import cached , qualname
@@ -84,9 +84,22 @@ def new(self, value, func):
8484 qualname (type (value ))))
8585
8686
87- def typed (func ):
88- from inspect import getfullargspec
89- spec = getfullargspec (func )
87+ def typed (func = None , argtypes = None , returntype = None ):
88+ if func is None :
89+ def typed (func ):
90+ global typed
91+ return typed (func , argtypes , returntype )
92+
93+ return typed
94+
95+ if argtypes is not None or returntype is not None :
96+ spec = getargspec (func )
97+ mtypes = {} if argtypes is None else dict (argtypes )
98+ mtypes ['return' ] = returntype
99+ else :
100+ from inspect import getfullargspec
101+ spec = getfullargspec (func )
102+ mtypes = spec .annotations
90103
91104 def typed (func , * args , ** kwargs ):
92105 iargs = iter (args )
@@ -103,5 +116,5 @@ def typed(func, *args, **kwargs):
103116 return result
104117
105118 wrapper = decorator (typed , func )
106- wrapper .mtypes = spec . annotations
119+ wrapper .mtypes = mtypes
107120 return wrapper
0 commit comments