Skip to content

Commit 6416a39

Browse files
committed
reformat
1 parent 6326d84 commit 6416a39

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

fgpyo/util/inspect.py

+9-31
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ def split_at_given_level(
5757
decrease_in_depth += high_level_split.count(char)
5858
outer_depth_of_split += increase_in_depth - decrease_in_depth
5959

60-
assert (
61-
outer_depth_of_split >= 0
62-
), "Unpaired depth character! Likely incorrect output"
60+
assert outer_depth_of_split >= 0, "Unpaired depth character! Likely incorrect output"
6361

6462
current_outer_splits.append(high_level_split)
6563
if outer_depth_of_split == 0:
6664
out_vals.append(split_delim.join(current_outer_splits))
6765
current_outer_splits = []
68-
assert (
69-
outer_depth_of_split == 0
70-
), "Unpaired depth character! Likely incorrect output!"
66+
assert outer_depth_of_split == 0, "Unpaired depth character! Likely incorrect output!"
7167
return out_vals
7268

7369

@@ -149,9 +145,7 @@ def get_parser() -> partial:
149145
if s == "{}"
150146
else [
151147
subtype_parser(item)
152-
for item in set(
153-
split_at_given_level(s[1:-1], split_delim=",")
154-
)
148+
for item in set(split_at_given_level(s[1:-1], split_delim=","))
155149
]
156150
)
157151
)
@@ -177,9 +171,7 @@ def tuple_parse(tuple_string: str) -> Tuple[Any, ...]:
177171
if len(tuple_string) == 0:
178172
return ()
179173
else:
180-
val_strings = split_at_given_level(
181-
tuple_string, split_delim=","
182-
)
174+
val_strings = split_at_given_level(tuple_string, split_delim=",")
183175
return tuple(
184176
parser(val_str)
185177
for parser, val_str in zip(subtype_parsers, val_strings)
@@ -215,14 +207,10 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
215207
if len(dict_string) == 0:
216208
return {}
217209
else:
218-
outer_splits = split_at_given_level(
219-
dict_string, split_delim=","
220-
)
210+
outer_splits = split_at_given_level(dict_string, split_delim=",")
221211
out_dict = {}
222212
for outer_split in outer_splits:
223-
inner_splits = split_at_given_level(
224-
outer_split, split_delim=";"
225-
)
213+
inner_splits = split_at_given_level(outer_split, split_delim=";")
226214
assert (
227215
len(inner_splits) % 2 == 0
228216
), "Inner splits of dict didn't have matched key val pairs"
@@ -242,18 +230,12 @@ def dict_parse(dict_string: str) -> Dict[Any, Any]:
242230
elif typing.get_origin(type_) is Union:
243231
return types.make_union_parser(
244232
union=type_,
245-
parsers=[
246-
_get_parser(cls, arg, parsers)
247-
for arg in typing.get_args(type_)
248-
],
233+
parsers=[_get_parser(cls, arg, parsers) for arg in typing.get_args(type_)],
249234
)
250235
elif typing.get_origin(type_) is Literal: # Py>=3.7.
251236
return types.make_literal_parser(
252237
type_,
253-
[
254-
_get_parser(cls, type(arg), parsers)
255-
for arg in typing.get_args(type_)
256-
],
238+
[_get_parser(cls, type(arg), parsers) for arg in typing.get_args(type_)],
257239
)
258240
else:
259241
raise ParserNotFoundException(
@@ -308,11 +290,7 @@ def attr_from(
308290
# try setting by casting
309291
# Note that while bools *can* be cast from string, all non-empty strings evaluate to
310292
# True, because python, so we need to check for that explicitly
311-
if (
312-
not set_value
313-
and attribute.type is not None
314-
and not attribute.type == bool
315-
):
293+
if not set_value and attribute.type is not None and not attribute.type == bool:
316294
try:
317295
return_value = attribute.type(str_value)
318296
set_value = True

fgpyo/util/types.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import TypeVar
1111
from typing import Union
1212

13-
1413
UnionType = TypeVar("UnionType", bound="Union")
1514
EnumType = TypeVar("EnumType", bound="Enum")
1615
# conceptually bound to "Literal" but that's not valid in the spec
@@ -103,9 +102,7 @@ def _make_union_parser_worker(
103102
raise ValueError(f"{value} could not be parsed as any of {union}")
104103

105104

106-
def make_union_parser(
107-
union: Type[UnionType], parsers: Iterable[Callable[[str], type]]
108-
) -> partial:
105+
def make_union_parser(union: Type[UnionType], parsers: Iterable[Callable[[str], type]]) -> partial:
109106
"""Generates a parser function for a union type object and set of parsers for the possible
110107
parsers to that union type object
111108
"""

0 commit comments

Comments
 (0)