@@ -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