MCPcopy Create free account
hub / github.com/vercel/vercel / _is_main_guard_test

Function _is_main_guard_test

python/vercel-runtime/src/vercel_runtime/utils.py:13–39  ·  view source on GitHub ↗
(node: ast.AST)

Source from the content-addressed store, hash-verified

11
12
13def _is_main_guard_test(node: ast.AST) -> bool:
14 if not isinstance(node, ast.Compare):
15 return False
16 if len(node.ops) != 1 or not isinstance(node.ops[0], ast.Eq):
17 return False
18 if len(node.comparators) != 1:
19 return False
20
21 left = node.left
22 right = node.comparators[0]
23
24 left_is_name = isinstance(left, ast.Name) and left.id == "__name__"
25 right_is_main = (
26 isinstance(right, ast.Constant)
27 and isinstance(right.value, str)
28 and right.value == "__main__"
29 )
30 if left_is_name and right_is_main:
31 return True
32
33 right_is_name = isinstance(right, ast.Name) and right.id == "__name__"
34 left_is_main = (
35 isinstance(left, ast.Constant)
36 and isinstance(left.value, str)
37 and left.value == "__main__"
38 )
39 return right_is_name and left_is_main
40
41
42def has_main_guard(entrypoint_abs: str | None) -> bool:

Callers 1

has_main_guardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected