@@ -40,7 +40,7 @@ def _native_names(tree: ast.Module) -> frozenset[str]:
4040 names .update (
4141 alias .asname or alias .name
4242 for alias in node .names
43- if native_module or NATIVE_MARKER in alias .name
43+ if native_module or _names_native ( alias .name )
4444 )
4545 elif isinstance (node , ast .Import ):
4646 names .update (
@@ -53,7 +53,11 @@ def _native_names(tree: ast.Module) -> frozenset[str]:
5353
5454def _is_native_module (module : str ) -> bool :
5555 parts : list [str ] = module .split ("." )
56- return parts [0 ] == NATIVE_PACKAGE and any (NATIVE_MARKER in part for part in parts [1 :])
56+ return parts [0 ] == NATIVE_PACKAGE and any (_names_native (part ) for part in parts [1 :])
57+
58+
59+ def _names_native (name : str ) -> bool :
60+ return NATIVE_MARKER in name .split ("_" )
5761
5862
5963def _guarded_blocks (tree : ast .Module ) -> list [tuple [str , ast .stmt ]]:
@@ -89,7 +93,17 @@ def _swallowing_lines(*, node: ast.stmt, native: frozenset[str]) -> list[int]:
8993
9094
9195def _always_raises (handler : ast .ExceptHandler ) -> bool :
92- return any (isinstance (statement , ast .Raise ) for statement in handler .body )
96+ return isinstance (handler .body [- 1 ], ast .Raise ) and not any (
97+ _exits_early (statement ) for statement in handler .body
98+ )
99+
100+
101+ def _exits_early (node : ast .AST ) -> bool :
102+ if isinstance (node , ast .Return | ast .Break | ast .Continue ):
103+ return True
104+ if isinstance (node , ast .FunctionDef | ast .AsyncFunctionDef | ast .Lambda | ast .ClassDef ):
105+ return False
106+ return any (_exits_early (child ) for child in ast .iter_child_nodes (node ))
93107
94108
95109def _is_suppress (expression : ast .expr ) -> bool :
0 commit comments