MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / SingleLineStatementTransformer

Class SingleLineStatementTransformer

scripts/prepare-for-update-assertions.py:32–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class SingleLineStatementTransformer(cst.CSTTransformer):
33 def __init__(self, function: str):
34 super().__init__()
35 self.function = function
36 self.in_function = False
37
38 def visit_FunctionDef(self, node: cst.FunctionDef):
39 if node.name.value == self.function:
40 self.in_function = True
41
42 def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef):
43 self.in_function = False
44 return updated_node
45
46 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.BaseExpression:
47 if self.in_function:
48 return updated_node.with_changes(
49 whitespace_after_func=SimpleWhitespace(""), whitespace_before_args=SimpleWhitespace("")
50 )
51 return updated_node
52
53 def leave_Arg(
54 self, original_node: cst.Arg, updated_node: cst.Arg
55 ) -> Union[cst.Arg, cst.FlattenSentinel[cst.Arg], cst.RemovalSentinel]:
56 if self.in_function:
57 return updated_node.with_changes(
58 whitespace_after_star=SimpleWhitespace(""), whitespace_after_arg=SimpleWhitespace("")
59 )
60 return updated_node
61
62 def leave_LeftParen(self, original_node: cst.LeftParen, updated_node: cst.LeftParen) -> cst.LeftParen:
63 if self.in_function:
64 return updated_node.with_changes(whitespace_after=SimpleWhitespace(""))
65 return updated_node
66
67 def leave_RightParen(self, original_node: cst.RightParen, updated_node: cst.RightParen) -> cst.RightParen:
68 if self.in_function:
69 return updated_node.with_changes(whitespace_before=SimpleWhitespace(""))
70 return updated_node
71
72 def leave_LeftCurlyBrace(
73 self, original_node: cst.LeftCurlyBrace, updated_node: cst.LeftCurlyBrace
74 ) -> cst.LeftCurlyBrace:
75 if self.in_function:
76 return updated_node.with_changes(whitespace_after=SimpleWhitespace(""))
77 return updated_node
78
79 def leave_RightCurlyBrace(
80 self, original_node: cst.RightCurlyBrace, updated_node: cst.RightCurlyBrace
81 ) -> cst.RightCurlyBrace:
82 if self.in_function:
83 return updated_node.with_changes(whitespace_before=SimpleWhitespace(""))
84 return updated_node
85
86 def leave_LeftSquareBracket(
87 self, original_node: cst.LeftSquareBracket, updated_node: cst.LeftSquareBracket
88 ) -> cst.LeftSquareBracket:
89 if self.in_function:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…