mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
Fix 'NoneType object is not subscriptable' error (#3286)
* fix: ensure none of the returned values is None Fixes TypeError 'NoneType' object is not subscriptable * refactor: reduce code duplication using a function * refactor: prefer KeyError over None for dicts If the key is not in the dictionary, we want to raise a KeyError rather than returning None. That way, we can distinguish between whether the value was None or the key was not found. * chore: add myself to CONTRIBUTORS file * refactor: simplify the code
This commit is contained in:
parent
426790bfcb
commit
a5a39c9302
1 changed files with 7 additions and 4 deletions
|
@ -1114,11 +1114,14 @@ def extract_meta_from_download_url(url: str) -> ExtractedDownloadMeta:
|
|||
urlobj = urlparse(url)
|
||||
query = parse_qs(urlobj.query)
|
||||
|
||||
def get_first_element(elements: list[str]) -> int:
|
||||
return int(elements[0])
|
||||
|
||||
meta = ExtractedDownloadMeta(
|
||||
mod_time=int(query.get("t")[0]),
|
||||
min_point_version=int(query.get("minpt")[0]),
|
||||
max_point_version=int(query.get("maxpt")[0]),
|
||||
branch_index=int(query.get("bidx")[0]),
|
||||
mod_time=get_first_element(query["t"]),
|
||||
min_point_version=get_first_element(query["minpt"]),
|
||||
max_point_version=get_first_element(query["maxpt"]),
|
||||
branch_index=get_first_element(query["bidx"]),
|
||||
)
|
||||
|
||||
return meta
|
||||
|
|
Loading…
Reference in a new issue