Skip to content

Commit e44871c

Browse files
committed
Fix check errors
Apparently I got something wrong in the CI rules somehow? Because they were already failing on #294 so that should not have been mergeable.
1 parent c3c3d96 commit e44871c

2 files changed

Lines changed: 40 additions & 37 deletions

File tree

src/ua_parser/__main__.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Deque,
1919
Dict,
2020
Iterable,
21+
Iterator,
2122
List,
2223
Optional,
2324
Sequence,
@@ -98,29 +99,31 @@ def get_rules(parsers: List[str], regexes: Optional[io.IOBase]) -> Matchers:
9899

99100

100101
def parse_item(item: str, all: list[str] | None) -> list[str]:
101-
if item == '*':
102+
if item == "*":
102103
assert all
103104
return all
104-
elif item.startswith('{'):
105-
assert item.endswith('}')
106-
return item[1:-1].split(',')
105+
elif item.startswith("{"):
106+
assert item.endswith("}")
107+
return item[1:-1].split(",")
107108
else:
108109
return [item]
109110

111+
110112
def rules_to_parsers(args: argparse.Namespace) -> Iterator[tuple[str, str, int]]:
111113
seen = set()
112114
for selector in args.selector:
113-
p, c, s = selector.split(':')
115+
p, c, s = selector.split(":")
114116
for triplet in (
115-
(pp, 'none' if ss == 0 else cc, ss)
116-
for pp in parse_item(p, ['basic', 're2', 'regex', 'legacy'])
117-
for cc in (parse_item(c, list(CACHES)) if CACHEABLE[pp] else ['none'])
118-
for ss in (map(int, parse_item(s, None)) if cc != 'none' else [0])
117+
(pp, "none" if ss == 0 else cc, ss)
118+
for pp in parse_item(p, ["basic", "re2", "regex", "legacy"])
119+
for cc in (parse_item(c, list(CACHES)) if CACHEABLE[pp] else ["none"])
120+
for ss in (map(int, parse_item(s, None)) if cc != "none" else [0])
119121
):
120122
if triplet not in seen:
121123
seen.add(triplet)
122124
yield triplet
123125

126+
124127
def run_stdout(args: argparse.Namespace) -> None:
125128
lines = list(map(sys.intern, args.file))
126129
count = len(lines)
@@ -132,15 +135,14 @@ def run_stdout(args: argparse.Namespace) -> None:
132135
rules = get_rules([*{p for p, _, _ in parsers}], args.regexes)
133136

134137
w = max(
135-
math.ceil(3 + len(p) + len(c) + (s and math.log10(s)))
136-
for p, c, s in parsers
138+
math.ceil(3 + len(p) + len(c) + (s and math.log10(s))) for p, c, s in parsers
137139
)
138140
for p, c, n in parsers:
139141
name = "-".join(map(str, filter(None, (p, c != "none" and c, n))))
140142
print(f"{name:{w}}", end=": ", flush=True)
141143

142-
p = get_parser(p, c, n, rules)
143-
t = run(p, lines)
144+
parser = get_parser(p, c, n, rules)
145+
t = run(parser, lines)
144146

145147
secs = t / 1e9
146148
tpl = t / 1000 / len(lines)
@@ -159,8 +161,7 @@ def run_csv(args: argparse.Namespace) -> None:
159161
rules = get_rules([*{p for p, _, _ in parsers}], args.regexes)
160162
columns = {"size": ""}
161163
columns.update(
162-
(f"{p}-{c}", p if c == "none" else f"{p}-{c}")
163-
for p, c, _ in parsers
164+
(f"{p}-{c}", p if c == "none" else f"{p}-{c}") for p, c, _ in parsers
164165
)
165166
w = csv.DictWriter(
166167
sys.stdout,
@@ -183,13 +184,15 @@ def run_csv(args: argparse.Namespace) -> None:
183184
# cache could be ignored as it should always be `"none"`
184185
for parser, cache, _ in ps:
185186
p = get_parser(parser, cache, 0, rules)
186-
zeroes[f"{parser}-{cache}"] = run(p, linges) // LEN
187+
zeroes[f"{parser}-{cache}"] = run(p, lines) // LEN
187188

188189
# special cases for configurations where we can't have
189190
# cachesize lines, write the template row out directly
190-
if all(p == 'legacy' for p, _, _ in parsers)\
191-
or all(c == 'none' for _, c, _ in parsers)\
192-
or all(s == 0 for _, _, s in parsers):
191+
if (
192+
all(p == "legacy" for p, _, _ in parsers)
193+
or all(c == "none" for _, c, _ in parsers)
194+
or all(s == 0 for _, _, s in parsers)
195+
):
193196
zeroes["size"] = 0
194197
w.writerow(zeroes)
195198
return
@@ -475,10 +478,10 @@ def __call__(
475478
nargs="*",
476479
default=["*:*:{10,20,50,100,200,500,1000,2000,5000}"],
477480
help=f"""A generative selector expression, composed of 3 parts: 1.
478-
the parser (base), 2. the cache implementation ({', '.join(CACHES)})
481+
the parser (base), 2. the cache implementation ({", ".join(CACHES)})
479482
and 3. the cache size. For parser and cache `*` is an alias for stands
480483
in for "every value", a bracketed expression for an enumeration, and
481-
the selector can be repeated to explicitly list each configuration """
484+
the selector can be repeated to explicitly list each configuration """,
482485
)
483486

484487
hitrates = sub.add_parser(

src/ua_parser/regex.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,29 @@ def __init__(self, matchers: Matchers) -> None:
4343
def __call__(self, ua: str, domains: Domain, /) -> PartialResult:
4444
user_agent = os = device = None
4545
if Domain.USER_AGENT in domains:
46-
if m := self.ua.extract(ua):
46+
if uam := self.ua.extract(ua):
4747
user_agent = UserAgent(
48-
m.family,
49-
m.major,
50-
m.minor,
51-
m.patch,
52-
m.patch_minor,
48+
uam.family,
49+
uam.major,
50+
uam.minor,
51+
uam.patch,
52+
uam.patch_minor,
5353
)
5454
if Domain.OS in domains:
55-
if m := self.os.extract(ua):
55+
if osm := self.os.extract(ua):
5656
os = OS(
57-
m.family,
58-
m.major,
59-
m.minor,
60-
m.patch,
61-
m.patch_minor,
57+
osm.family,
58+
osm.major,
59+
osm.minor,
60+
osm.patch,
61+
osm.patch_minor,
6262
)
6363
if Domain.DEVICE in domains:
64-
if m := self.de.extract(ua):
64+
if dem := self.de.extract(ua):
6565
device = Device(
66-
m.family,
67-
m.brand,
68-
m.model,
66+
dem.family,
67+
dem.brand,
68+
dem.model,
6969
)
7070
return PartialResult(
7171
domains=domains,

0 commit comments

Comments
 (0)