MCPcopy Index your code
hub / github.com/python/cpython / parse

Function parse

Lib/ast.py:26–48  ·  view source on GitHub ↗

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, optimize=-1, module=None)

Source from the content-addressed store, hash-verified

24
25
26def parse(source, filename='<unknown>', mode='exec', *,
27 type_comments=False, feature_version=None, optimize=-1, module=None):
28 """
29 Parse the source into an AST node.
30 Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
31 Pass type_comments=True to get back type comments where the syntax allows.
32 """
33 flags = PyCF_ONLY_AST
34 if optimize > 0:
35 flags |= PyCF_OPTIMIZED_AST
36 if type_comments:
37 flags |= PyCF_TYPE_COMMENTS
38 if feature_version is None:
39 feature_version = -1
40 elif isinstance(feature_version, tuple):
41 major, minor = feature_version # Should be a 2-tuple.
42 if major != 3:
43 raise ValueError(f"Unsupported major version: {major}")
44 feature_version = minor
45 # Else it should be an int giving the minor version for 3.x.
46 return compile(source, filename, mode, flags,
47 _feature_version=feature_version, optimize=optimize,
48 module=module)
49
50
51def literal_eval(node_or_string):

Callers 2

literal_evalFunction · 0.70
mainFunction · 0.70

Calls 1

compileFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…