@@ -59,15 +59,15 @@ def _get_module_description(path: Path) -> str | None:
5959 content = init_file .read_text ()
6060 tree = ast .parse (content )
6161 return ast .get_docstring (tree )
62- except Exception :
63- pass
62+ except Exception : # nosec B110
63+ pass # Silently ignore unparseable files
6464 elif path .suffix == ".py" :
6565 try :
6666 content = path .read_text ()
6767 tree = ast .parse (content )
6868 return ast .get_docstring (tree )
69- except Exception :
70- pass
69+ except Exception : # nosec B110
70+ pass # Silently ignore unparseable files
7171 return None
7272
7373
@@ -125,9 +125,7 @@ def _count_modules(node: ModuleNode) -> tuple[int, int]:
125125 return modules , files
126126
127127
128- def _parse_python_file (path : Path ) -> tuple [
129- list [ClassInfo ], list [FunctionInfo ], list [str ], str | None
130- ]:
128+ def _parse_python_file (path : Path ) -> tuple [list [ClassInfo ], list [FunctionInfo ], list [str ], str | None ]:
131129 """Parse a Python file and extract classes, functions, and imports."""
132130 content = path .read_text ()
133131 tree = ast .parse (content )
@@ -193,8 +191,8 @@ def _parse_python_file(path: Path) -> tuple[
193191
194192def _get_attribute_name (node : ast .Attribute ) -> str :
195193 """Get the full name of an attribute access."""
196- parts = []
197- current = node
194+ parts : list [ str ] = []
195+ current : ast . expr = node
198196 while isinstance (current , ast .Attribute ):
199197 parts .append (current .attr )
200198 current = current .value
@@ -288,7 +286,7 @@ def get_file_content(path: str) -> FileContent:
288286 if not str (file_path ).startswith (str (fusion_root .resolve ())):
289287 raise HTTPException (status_code = 403 , detail = "Access denied" )
290288 except Exception :
291- raise HTTPException (status_code = 400 , detail = "Invalid path" )
289+ raise HTTPException (status_code = 400 , detail = "Invalid path" ) from None
292290
293291 if not file_path .exists ():
294292 raise HTTPException (status_code = 404 , detail = f"File not found: { path } " )
@@ -325,9 +323,9 @@ def get_file_content(path: str) -> FileContent:
325323 if suffix == ".py" :
326324 try :
327325 classes , functions , imports , docstring = _parse_python_file (file_path )
328- except SyntaxError :
326+ except SyntaxError : # nosec B110
329327 pass # Invalid Python syntax, just return content
330- except Exception :
328+ except Exception : # nosec B110
331329 pass # Other parsing errors
332330
333331 return FileContent (
@@ -373,12 +371,14 @@ def search_codebase(q: str, limit: int = 20) -> list[dict]:
373371
374372 # Match file name
375373 if query in file .lower ():
376- results .append ({
377- "type" : "file" ,
378- "name" : file ,
379- "path" : rel_path ,
380- "match" : "filename" ,
381- })
374+ results .append (
375+ {
376+ "type" : "file" ,
377+ "name" : file ,
378+ "path" : rel_path ,
379+ "match" : "filename" ,
380+ }
381+ )
382382
383383 # For Python files, also search classes and functions
384384 if file .endswith (".py" ) and len (results ) < limit :
@@ -389,24 +389,28 @@ def search_codebase(q: str, limit: int = 20) -> list[dict]:
389389 for node in ast .iter_child_nodes (tree ):
390390 if isinstance (node , ast .ClassDef ):
391391 if query in node .name .lower ():
392- results .append ({
393- "type" : "class" ,
394- "name" : node .name ,
395- "path" : rel_path ,
396- "line" : node .lineno ,
397- "match" : "class" ,
398- })
392+ results .append (
393+ {
394+ "type" : "class" ,
395+ "name" : node .name ,
396+ "path" : rel_path ,
397+ "line" : node .lineno ,
398+ "match" : "class" ,
399+ }
400+ )
399401 elif isinstance (node , ast .FunctionDef | ast .AsyncFunctionDef ):
400402 if query in node .name .lower ():
401- results .append ({
402- "type" : "function" ,
403- "name" : node .name ,
404- "path" : rel_path ,
405- "line" : node .lineno ,
406- "match" : "function" ,
407- })
408- except Exception :
409- pass
403+ results .append (
404+ {
405+ "type" : "function" ,
406+ "name" : node .name ,
407+ "path" : rel_path ,
408+ "line" : node .lineno ,
409+ "match" : "function" ,
410+ }
411+ )
412+ except Exception : # nosec B110
413+ pass # Skip files that can't be parsed
410414
411415 if len (results ) >= limit :
412416 break
0 commit comments