Skip to content

Commit b3e6e3a

Browse files
Restyled by black
1 parent f76d80a commit b3e6e3a

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

test/core_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def test_set_status_message(self):
6161

6262
tox.status_message = b"x" * core.MAX_STATUS_MESSAGE_LENGTH
6363
with self.assertRaises(error.ApiException):
64-
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH +
65-
1)
64+
tox.status_message = b"x" * (core.MAX_STATUS_MESSAGE_LENGTH + 1)
6665

6766
def test_set_status(self):
6867
with core.Core() as tox:

tools/gen_api.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def needs_space(l: str, r: str) -> bool:
3737
def untokenize(tokens: Tuple[str, ...]) -> str:
3838
line = []
3939
for i in range(len(tokens) - 1):
40-
if tokens[i:i + 2] == ("void", ")"):
40+
if tokens[i : i + 2] == ("void", ")"):
4141
break
4242
line.append(tokens[i])
4343
if needs_space(tokens[i], tokens[i + 1]):
@@ -74,10 +74,11 @@ def parse_params(tokens: Tuple[str, ...]) -> List[Tuple[List[str], str]]:
7474
return params
7575

7676

77-
def finalize_handler(type_prefix: str, handlers: List[str], event: str,
78-
params: List[str]) -> None:
77+
def finalize_handler(
78+
type_prefix: str, handlers: List[str], event: str, params: List[str]
79+
) -> None:
7980
handlers[-1] += " noexcept:"
80-
#handlers[-1] += ":"
81+
# handlers[-1] += ":"
8182
self = ""
8283
array = ""
8384
args = []
@@ -133,8 +134,9 @@ def handle_macro(tokens: Sequence[str], state: List[str]) -> bool:
133134
return False
134135

135136

136-
def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
137-
const_prefix: str) -> bool:
137+
def handle_types(
138+
tokens: Sequence[str], state: List[str], extern: List[str], const_prefix: str
139+
) -> bool:
138140
# struct definitions (members are ignored)
139141
if tokens[0] == "struct" and tokens[-1] == "{":
140142
state.append("struct")
@@ -146,8 +148,7 @@ def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
146148
extern.append(f" ctypedef struct {tokens[2]}")
147149

148150
# enums
149-
if (tokens[:2] == ("typedef", "enum")
150-
or tokens[0] == "enum") and tokens[-1] == "{":
151+
if (tokens[:2] == ("typedef", "enum") or tokens[0] == "enum") and tokens[-1] == "{":
151152
enum_name = tokens[-2]
152153
if enum_name != "Tox_Log_Level":
153154
extern.append("")
@@ -162,38 +163,41 @@ def handle_types(tokens: Sequence[str], state: List[str], extern: List[str],
162163

163164

164165
def handle_functions(
165-
tokens: Tuple[str, ...],
166-
state: List[str],
167-
extern: List[str],
168-
fun_prefix: str,
169-
type_prefix: str,
170-
event: str,
171-
params: List[str],
172-
handlers: List[str],
173-
install_handlers: List[str],
166+
tokens: Tuple[str, ...],
167+
state: List[str],
168+
extern: List[str],
169+
fun_prefix: str,
170+
type_prefix: str,
171+
event: str,
172+
params: List[str],
173+
handlers: List[str],
174+
install_handlers: List[str],
174175
) -> str:
175176
# functions and callbacks
176-
if ("(" in tokens and tokens[0].isidentifier()
177-
and token_before("(", tokens).startswith(fun_prefix)
178-
and tokens[0] != "typedef"):
177+
if (
178+
"(" in tokens
179+
and tokens[0].isidentifier()
180+
and token_before("(", tokens).startswith(fun_prefix)
181+
and tokens[0] != "typedef"
182+
):
179183
extern.append(f" cdef {untokenize_fun(tokens)}")
180184
if ";" not in tokens:
181185
state.append("fun")
182186
return event
183187
if tokens[:2] == ("typedef", "void"):
184188
extern.append(f" c{untokenize_fun(tokens)}")
185189

186-
event = tokens[2][len(fun_prefix):-3]
190+
event = tokens[2][len(fun_prefix) : -3]
187191
params.clear()
188192
params.extend(tokens[3:])
189193

190194
# TODO(iphydf): Handle this better (by checking whether we have a callback install
191195
# function for this event).
192196
if event != "log":
193-
handlers.append(
194-
f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
197+
handlers.append(f"cdef void handle_{untokenize_fun((event,) + tokens[3:])}")
195198
install_handlers.append(
196-
f" {fun_prefix}callback_{event}(ptr, handle_{event})")
199+
f" {fun_prefix}callback_{event}(ptr, handle_{event})"
200+
)
197201
if ";" not in tokens:
198202
state.append("callback")
199203
else:
@@ -278,8 +282,7 @@ def gen_cython(lines: Sequence[str], fun_prefix: str, extern_line: str) -> List[
278282
)
279283

280284
if install_handlers:
281-
install_handlers = (
282-
["cdef void install_handlers(Tox *ptr):"] + install_handlers)
285+
install_handlers = ["cdef void install_handlers(Tox *ptr):"] + install_handlers
283286
return extern + [""] + handlers + [""] + install_handlers
284287

285288

@@ -292,13 +295,15 @@ def main() -> None:
292295
if line.startswith("cdef extern from"):
293296
extern_line = line.removesuffix(" pass\n")
294297
with open(api, "r", encoding="utf-8") as api_fh:
295-
print("\n".join(
296-
gen_cython(
297-
api_fh.readlines(),
298-
fun_prefix=os.path.split(api)[-1].split(".")[0] +
299-
"_",
300-
extern_line=extern_line,
301-
)))
298+
print(
299+
"\n".join(
300+
gen_cython(
301+
api_fh.readlines(),
302+
fun_prefix=os.path.split(api)[-1].split(".")[0] + "_",
303+
extern_line=extern_line,
304+
)
305+
)
306+
)
302307
else:
303308
print(line.rstrip())
304309

0 commit comments

Comments
 (0)