Try reading a Python file as list of source lines. Return None if something goes wrong.
(path: str, read: Callable[[str], bytes])
| 179 | |
| 180 | |
| 181 | def 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 | |
| 198 | def trim_source_line(line: str, max_len: int, col: int, min_width: int) -> tuple[str, int]: |
no test coverage detected
searching dependent graphs…