Skip to content

Commit

Permalink
Cover azul.azulclient with mypy (#6821)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Jan 16, 2025
1 parent 480e1fe commit dc73729
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
11 changes: 10 additions & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ explicit_package_bases = True
modules =
azul.types,
azul.collections,
azul.auth
azul.args,
azul.attrs,
azul.auth,
azul.azulclient

[mypy-furl.*]
follow_untyped_imports = True

[mypy-requests.*]
follow_untyped_imports = True
28 changes: 14 additions & 14 deletions src/azul/azulclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def notification(self, bundle_fqid: SourcedBundleFQID) -> JSON:
# only variant that would ever occur in the wild.
return {
'transaction_id': str(uuid.uuid4()),
'bundle_fqid': bundle_fqid.to_json()
'bundle_fqid': cast(JSON, bundle_fqid.to_json())
}

def bundle_message(self,
Expand All @@ -115,7 +115,7 @@ def reindex_message(self,
return {
'action': 'reindex',
'catalog': catalog,
'source': source.to_json(),
'source': cast(JSON, source.to_json()),
'prefix': prefix
}

Expand All @@ -133,7 +133,7 @@ def index(self,
notifications: Iterable[JSON],
delete: bool = False
):
errors = defaultdict(int)
errors = defaultdict[int, int](int)
missing = []
indexed = 0
total = 0
Expand Down Expand Up @@ -247,16 +247,16 @@ def remote_reindex(self,
sources: Set[str]):

plugin = self.repository_plugin(catalog)
for source in sources:
source = plugin.resolve_source(source)
source = plugin.partition_source(catalog, source)
for source_spec in sources:
source_ref = plugin.resolve_source(source_spec)
source_ref = plugin.partition_source(catalog, source_ref)

def message(partition_prefix: str) -> JSON:
log.info('Remotely reindexing prefix %r of source %r into catalog %r',
partition_prefix, str(source.spec), catalog)
return self.reindex_message(catalog, source, partition_prefix)
log.info('Remotely reindexing prefix %r of source_ref %r into catalog %r',
partition_prefix, str(source_ref.spec), catalog)
return self.reindex_message(catalog, source_ref, partition_prefix)

messages = map(message, source.spec.prefix.partition_prefixes())
messages = map(message, source_ref.spec.prefix.partition_prefixes())
for batch in chunked(messages, 10):
entries = [
dict(Id=str(i), MessageBody=json.dumps(message))
Expand All @@ -265,8 +265,8 @@ def message(partition_prefix: str) -> JSON:
self.notifications_queue.send_messages(Entries=entries)

def remote_reindex_partition(self, message: JSON) -> None:
catalog = message['catalog']
prefix = message['prefix']
catalog, prefix = message['catalog'], message['prefix']
assert isinstance(catalog, str) and isinstance(prefix, str)
# FIXME: Adopt `trycast` for casting JSON to TypeDict
# https://github.com/DataBiosphere/azul/issues/5171
source = cast(SourceJSON, message['source'])
Expand Down Expand Up @@ -386,11 +386,11 @@ def group_key(fqid: SourcedBundleFQID):
fqid.uuid.lower()
)

bundle_fqids = groupby(bundle_fqids, key=group_key)
groups = groupby(bundle_fqids, key=group_key)

# Take the first item in each group. Because the oder is reversed, this
# is the latest version
bundle_fqids = [next(group) for _, group in bundle_fqids]
bundle_fqids = [next(group) for _, group in groups]
return bundle_fqids

@cached_property
Expand Down

0 comments on commit dc73729

Please sign in to comment.