@@ -305,7 +305,7 @@ def visit_If(self, node: ast.If) -> Iterable[NameInfo]:
305305 yield from self .visit (stmt )
306306
307307 def _visit_condition (self , expr : ast .expr ) -> Optional [bool ]:
308- visitor = _LiteralEvalVisitor (self .ctx , self .file_path )
308+ visitor = LiteralEvalVisitor (self .ctx , self .file_path )
309309 try :
310310 value = visitor .visit (expr )
311311 except InvalidStub :
@@ -430,7 +430,17 @@ def generic_visit(self, node: ast.AST) -> Iterable[NameInfo]:
430430 raise InvalidStub (f"Cannot handle node { ast .dump (node )} " , self .file_path )
431431
432432
433- class _LiteralEvalVisitor (ast .NodeVisitor ):
433+ class LiteralEvalVisitor (ast .NodeVisitor ):
434+ """Visitor to evaluate the truthiness of a ``test`` expression in an ``ast.Compare`` node.
435+
436+ ``LiteralEvalVisitor(ctx, path).visit(node)`` will return ``True`` if ``node`` is an
437+ expression that can be statically determined to always be ``True``, ``False`` if it can
438+ be statically determined to always be ``False``, and ``None`` if its truthiness cannot
439+ be determined statically. For example, if passed an AST node representing the expression
440+ ``sys.platform == "linux"``, it will return ``True`` if ``ctx.platform`` is equal to
441+ ``"linux"``, otherwise ``False``.
442+ """
443+
434444 def __init__ (self , ctx : SearchContext , file_path : Optional [Path ]) -> None :
435445 self .ctx = ctx
436446 self .file_path = file_path
0 commit comments