summaryrefslogtreecommitdiff
path: root/venv/Lib/site-packages/astroid/_ast.py
diff options
context:
space:
mode:
authorlucaszhao192020-02-05 18:02:20 +0530
committerlucaszhao192020-02-05 18:02:20 +0530
commitae7090629a8beae3064eee7128856d5d3aeaa604 (patch)
tree939eedc5d96fd17bc5af34bde6524d3e4b3a7cfa /venv/Lib/site-packages/astroid/_ast.py
parent38dbff48f57c403abdc575a9cd9d0bbf512bfef6 (diff)
parent190966e010e321e4df56d40104ec80467a870e53 (diff)
downloadChemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.tar.gz
Chemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.tar.bz2
Chemical-Simulator-GUI-ae7090629a8beae3064eee7128856d5d3aeaa604.zip
Revamped and merged Input/Results DockWidgets, Newly implemented variables for MaterialStream and four UnitOps
Diffstat (limited to 'venv/Lib/site-packages/astroid/_ast.py')
-rw-r--r--venv/Lib/site-packages/astroid/_ast.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/venv/Lib/site-packages/astroid/_ast.py b/venv/Lib/site-packages/astroid/_ast.py
new file mode 100644
index 0000000..2e44c1f
--- /dev/null
+++ b/venv/Lib/site-packages/astroid/_ast.py
@@ -0,0 +1,49 @@
+import ast
+from collections import namedtuple
+from functools import partial
+from typing import Optional
+import sys
+
+_ast_py2 = _ast_py3 = None
+try:
+ import typed_ast.ast3 as _ast_py3
+ import typed_ast.ast27 as _ast_py2
+except ImportError:
+ pass
+
+
+PY38 = sys.version_info[:2] >= (3, 8)
+if PY38:
+ # On Python 3.8, typed_ast was merged back into `ast`
+ _ast_py3 = ast
+
+
+FunctionType = namedtuple("FunctionType", ["argtypes", "returns"])
+
+
+def _get_parser_module(parse_python_two: bool = False):
+ if parse_python_two:
+ parser_module = _ast_py2
+ else:
+ parser_module = _ast_py3
+ return parser_module or ast
+
+
+def _parse(string: str, parse_python_two: bool = False):
+ parse_module = _get_parser_module(parse_python_two=parse_python_two)
+ parse_func = parse_module.parse
+ if _ast_py3:
+ if PY38:
+ parse_func = partial(parse_func, type_comments=True)
+ if not parse_python_two:
+ parse_func = partial(parse_func, feature_version=sys.version_info.minor)
+ return parse_func(string)
+
+
+def parse_function_type_comment(type_comment: str) -> Optional[FunctionType]:
+ """Given a correct type comment, obtain a FunctionType object"""
+ if _ast_py3 is None:
+ return None
+
+ func_type = _ast_py3.parse(type_comment, "<type_comment>", "func_type")
+ return FunctionType(argtypes=func_type.argtypes, returns=func_type.returns)