MCPcopy
hub / github.com/python/mypy / read_py_file

Function read_py_file

mypy/util.py:181–195  ·  view source on GitHub ↗

Try reading a Python file as list of source lines. Return None if something goes wrong.

(path: str, read: Callable[[str], bytes])

Source from the content-addressed store, hash-verified

179
180
181def read_py_file(path: str, read: Callable[[str], bytes]) -> list[str] | None:
182 """Try reading a Python file as list of source lines.
183
184 Return None if something goes wrong.
185 """
186 try:
187 source = read(path)
188 except OSError:
189 return None
190 else:
191 try:
192 source_lines = decode_python_encoding(source).splitlines()
193 except DecodeError:
194 return None
195 return source_lines
196
197
198def trim_source_line(line: str, max_len: int, col: int, min_width: int) -> tuple[str, int]:

Callers 2

build_innerFunction · 0.90
mainFunction · 0.90

Calls 2

decode_python_encodingFunction · 0.85
splitlinesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…