def _parse_text(source: Union[str, NodeNG]) -> Tuple[astroid.Module, TypeInferer]:
"""Parse source code text and output an AST with type inference performed."""
# TODO: apparently no literal syntax for empty set in Python3, also cannot do set()
# TODO: Deal with special case later.
# if isinstance(source, astroid.Set) and len(list(source.elts)) == 0:
# source = f'{set({})}'
if not isinstance(source, str): # It's an astroid node
source = source.as_string()
module = astroid.parse(source)
type_inferer = TypeInferer()
type_inferer.environment_transformer().visit(module)
type_inferer.type_inference_transformer().visit(module)
return module, type_inferer
评论列表
文章目录