218 @param literal AST literal to be converted |
217 @param literal AST literal to be converted |
219 @type ast.AST |
218 @type ast.AST |
220 @return converted Python object |
219 @return converted Python object |
221 @rtype Any |
220 @rtype Any |
222 """ |
221 """ |
223 if AstUtilities.isNumber(literal): |
222 if ( |
224 literalValue = literal.n |
223 AstUtilities.isNumber(literal) |
225 |
224 or AstUtilities.isString(literal) |
226 elif AstUtilities.isString(literal) or AstUtilities.isBytes(literal): |
225 or AstUtilities.isBytes(literal) |
227 literalValue = literal.s |
226 ): |
|
227 literalValue = literal.value |
228 |
228 |
229 elif isinstance(literal, ast.List): |
229 elif isinstance(literal, ast.List): |
230 returnList = [] |
230 returnList = [] |
231 for li in literal.elts: |
231 for li in literal.elts: |
232 returnList.append(self.__getLiteralValue(li)) |
232 returnList.append(self.__getLiteralValue(li)) |
245 literalValue = returnSet |
245 literalValue = returnSet |
246 |
246 |
247 elif isinstance(literal, ast.Dict): |
247 elif isinstance(literal, ast.Dict): |
248 literalValue = dict(zip(literal.keys, literal.values)) |
248 literalValue = dict(zip(literal.keys, literal.values)) |
249 |
249 |
250 elif sys.version_info <= (3, 8, 0) and isinstance(literal, ast.Ellipsis): |
250 elif AstUtilities.isEllipsis(literal): |
251 # what do we want to do with this? |
251 # what do we want to do with this? |
252 literalValue = None |
252 literalValue = None |
253 |
253 |
254 elif isinstance(literal, ast.Name): |
254 elif isinstance(literal, ast.Name): |
255 literalValue = literal.id |
255 literalValue = literal.id |