MCPcopy
hub / github.com/psf/black / parse_ast

Function parse_ast

src/black/parsing.py:143–162  ·  view source on GitHub ↗
(src: str)

Source from the content-addressed store, hash-verified

141
142
143def parse_ast(src: str) -> ast.AST:
144 # TODO: support Python 4+ ;)
145 versions = [(3, minor) for minor in range(3, sys.version_info[1] + 1)]
146
147 first_error = ""
148 for version in sorted(versions, reverse=True):
149 try:
150 return _parse_single_version(src, version, type_comments=True)
151 except SyntaxError as e:
152 if not first_error:
153 first_error = str(e)
154
155 # Try to parse without type comments
156 for version in sorted(versions, reverse=True):
157 try:
158 return _parse_single_version(src, version, type_comments=False)
159 except SyntaxError:
160 pass
161
162 raise SyntaxError(first_error)
163
164
165def _normalize(lineend: str, value: str) -> str:

Callers 1

assert_equivalentFunction · 0.90

Calls 1

_parse_single_versionFunction · 0.85

Tested by

no test coverage detected