Parse the source into an AST node. Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). Pass type_comments=True to get back type comments where the syntax allows.
(source, filename='<unknown>', mode='exec', *,
type_comments=False, feature_version=None)
| 31 | |
| 32 | |
| 33 | def parse(source, filename='<unknown>', mode='exec', *, |
| 34 | type_comments=False, feature_version=None): |
| 35 | """ |
| 36 | Parse the source into an AST node. |
| 37 | Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). |
| 38 | Pass type_comments=True to get back type comments where the syntax allows. |
| 39 | """ |
| 40 | flags = PyCF_ONLY_AST |
| 41 | if type_comments: |
| 42 | flags |= PyCF_TYPE_COMMENTS |
| 43 | if isinstance(feature_version, tuple): |
| 44 | major, minor = feature_version # Should be a 2-tuple. |
| 45 | assert major == 3 |
| 46 | feature_version = minor |
| 47 | elif feature_version is None: |
| 48 | feature_version = -1 |
| 49 | # Else it should be an int giving the minor version for 3.x. |
| 50 | return compile(source, filename, mode, flags, |
| 51 | _feature_version=feature_version) |
| 52 | |
| 53 | |
| 54 | def literal_eval(node_or_string): |
no test coverage detected