Skip to content

Commit a0ab406

Browse files
committed
Fix some typing issues in src/conftest.py
These errors went unnoticed in the past because the file wasn't being checked by `mypy`. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 324e1b7 commit a0ab406

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/conftest.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ def get_import_statements(code: str) -> list[str]:
4242
A list of import statements.
4343
"""
4444
tree = ast.parse(code)
45-
import_statements = []
45+
import_statements: list[str] = []
4646

4747
for node in ast.walk(tree):
4848
if isinstance(node, (ast.Import, ast.ImportFrom)):
4949
import_statement = ast.get_source_segment(code, node)
50+
assert import_statement is not None
5051
import_statements.append(import_statement)
5152

5253
return import_statements
@@ -85,7 +86,9 @@ def path_to_import_statement(path: Path) -> str:
8586
return import_statement
8687

8788

88-
class CustomPythonCodeBlockParser(CodeBlockParser):
89+
# We need to add the type ignore comment here because the Sybil library does not
90+
# have type annotations.
91+
class CustomPythonCodeBlockParser(CodeBlockParser): # type: ignore[misc]
8992
"""Code block parser that validates extracted code examples using pylint.
9093
9194
This parser is a modified version of the default Python code block parser
@@ -103,7 +106,7 @@ class CustomPythonCodeBlockParser(CodeBlockParser):
103106
Pylint warnings which are unimportant for code examples are disabled.
104107
"""
105108

106-
def __init__(self):
109+
def __init__(self) -> None:
107110
"""Initialize the parser."""
108111
super().__init__("python")
109112

@@ -199,7 +202,9 @@ def validate_with_pylint(
199202
check=True,
200203
)
201204
except subprocess.CalledProcessError as exception:
202-
return exception.output.splitlines()
205+
output = exception.output
206+
assert isinstance(output, str)
207+
return output.splitlines()
203208

204209
return []
205210

0 commit comments

Comments
 (0)