Skip to content

Commit

Permalink
fix(typing): Resolve some mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Oct 11, 2024
1 parent 31eeb20 commit 511a845
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions tools/vendor_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import os
import random
import sys
import tempfile
import time
import urllib.request
Expand All @@ -24,18 +25,23 @@
Callable,
ClassVar,
Iterable,
Iterator,
Literal,
NamedTuple,
Sequence,
TypedDict,
cast,
get_args,
)
from urllib.request import urlopen

import polars as pl

if sys.version_info >= (3, 14):
from typing import TypedDict
else:
from typing_extensions import TypedDict

if TYPE_CHECKING:
import sys
from email.message import Message
from typing import MutableMapping, TypeVar
from urllib.request import OpenerDirector, Request
Expand Down Expand Up @@ -147,8 +153,15 @@ class ParsedTree(TypedDict):
tag: str


class QueryTree(ParsedTree, total=False):
class QueryTree(TypedDict, total=False):
file_name: str
name_js: Required[str]
name_py: str
suffix: str
size: int
url: str
ext_supported: bool
tag: str


class ParsedTreesResponse(TypedDict):
Expand Down Expand Up @@ -501,13 +514,10 @@ def refresh(
print(f"Already up-to-date {fp_trees!s}")
return trees
else:
missing = (
ReParsedTag(**row)
for row in islice(
missing_trees.iter_rows(named=True),
None if IS_AUTH else UNAUTH_LIMIT,
)
it = islice(
missing_trees.iter_rows(named=True), None if IS_AUTH else UNAUTH_LIMIT
)
missing = cast("Iterator[ReParsedTag]", it)
fresh_rows = self._trees_batched(missing)
print(
f"Finished collection.\n"
Expand Down Expand Up @@ -847,14 +857,16 @@ def __call__(
if name.endswith(get_args(ExtSupported)):
name, suffix = name.rsplit(".", maxsplit=1)
suffix = "." + suffix
else:
suffix = ext
if suffix is not None:
if not is_ext_supported(suffix):
raise TypeError(suffix)
else:
constraints["suffix"] = suffix
q = QueryTree(name_js=name, **constraints)
elif ext is not None:
if not is_ext_supported(ext):
raise TypeError(ext)
else:
constraints["suffix"] = ext
q = QueryTree(name_js=name, **constraints) # type: ignore[typeddict-item]
return GitHub.query.url_from(**q)


Expand Down

0 comments on commit 511a845

Please sign in to comment.