@@ -92,22 +92,6 @@ def example7(self, arg1, arg2=None, *varargs, **kwargs): # pylint: disable=keyw
92
92
return arg1 , arg2 , varargs , kwargs
93
93
94
94
95
- if sys .version_info >= (3 , 5 ):
96
- from pathlib import Path
97
-
98
-
99
- class WithTypeHints (object ):
100
-
101
- @decorators .UseTypeHints ()
102
- def example8 (self , a : int , b : str , c , d : float = None ):
103
- return a , b , c , d
104
-
105
- @decorators .UseTypeHints ({list : lambda arg : list (map (int , arg .split (";" ))),
106
- Path : Path })
107
- def example9 (self , a : Path , b , c : list , d : list = None ):
108
- return a , b , c , d
109
-
110
-
111
95
class FireDecoratorsTest (testutils .BaseTestCase ):
112
96
113
97
def testSetParseFnsNamedArgs (self ):
@@ -190,19 +174,39 @@ def testSetParseFn(self):
190
174
@unittest .skipIf (sys .version_info < (3 , 5 ),
191
175
'Type hints were introduced in python 3.5' )
192
176
def testDefaultTypeHints (self ):
177
+ # need to hide type hints syntax behind exec
178
+ # otherwise old python parser will fail
179
+ #pylint: disable=exec-used
180
+ exec ("""@decorators.UseTypeHints()
181
+ def exampleWithSimpleTypeHints(a: int, b: str, c, d : float = None):
182
+ return a, b, c, d""" )
183
+
184
+
193
185
self .assertEqual (
194
- core .Fire (WithTypeHints ,
195
- command = ['example8' , ' 1' , '2' , '3' , '--d=4' ]),
186
+ core .Fire (locals ()[ 'exampleWithSimpleTypeHints' ] ,
187
+ command = ['1' , '2' , '3' , '--d=4' ]),
196
188
(1 , '2' , 3 , 4 )
197
189
)
198
190
199
191
@unittest .skipIf (sys .version_info < (3 , 5 ),
200
192
'Type hints were introduced in python 3.5' )
201
193
def testCustomTypeHints (self ):
194
+ # need to hide type hints syntax behind exec
195
+ # otherwise old python parser will fail
196
+ #pylint: disable=exec-used
197
+ exec ("""from pathlib import Path
198
+
199
+
200
+ @decorators.UseTypeHints({
201
+ list: lambda arg: list(map(int, arg.split(";"))),
202
+ Path: Path})
203
+ def exampleWithComplexHints(a: Path, b, c: list, d : list = None):
204
+ return a, b, c, d""" )
205
+
202
206
self .assertEqual (
203
- core .Fire (WithTypeHints ,
204
- command = ['example9' , ' 1' , '2' , '3' , '--d=4;5;6' ]),
205
- (Path ('1' ), 2 , [3 ], [4 , 5 , 6 ])
207
+ core .Fire (locals ()[ 'exampleWithComplexHints' ] ,
208
+ command = ['1' , '2' , '3' , '--d=4;5;6' ]),
209
+ (locals ()[ ' Path' ] ('1' ), 2 , [3 ], [4 , 5 , 6 ])
206
210
)
207
211
208
212
0 commit comments