Skip to content

Commit

Permalink
Fix mypy complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed May 10, 2021
1 parent 431ac1d commit 81635cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions python/lsst/daf/butler/datastores/fileDatastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,13 @@ def emptyTrash(self, ignore_errors: bool = True) -> None:
if isinstance(info, StoredFileInfo)])

for ref, info in trashed:

# Mypy needs to know this is not the base class
assert isinstance(info, StoredFileInfo), f"Unexpectedly got info of class {type(info)}"

# Check for mypy
assert ref.id is not None, f"Internal logic error in emptyTrash with ref {ref}/{info}"

path_map[info.path].remove(ref.id)
if not path_map[info.path]:
del path_map[info.path]
Expand Down
3 changes: 2 additions & 1 deletion python/lsst/daf/butler/registry/bridge/ephemeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def emptyTrash(self, records_table: Optional[OpaqueTableStorage] = None,
record_column: Optional[str] = None,
) -> Iterator[Tuple[Iterable[Tuple[DatasetIdRef,
Optional[StoredDatastoreItemInfo]]],
Set[str]]]:
Optional[Set[str]]]]:
# Docstring inherited from DatastoreRegistryBridge
matches: Iterable[Tuple[FakeDatasetRef, Optional[StoredDatastoreItemInfo]]] = ()
if isinstance(records_table, OpaqueTableStorage):
if record_class is None:
raise ValueError("Record class must be provided if records table is given.")
Expand Down
8 changes: 5 additions & 3 deletions python/lsst/daf/butler/registry/bridge/monolithic.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,23 @@ def emptyTrash(self, records_table: Optional[OpaqueTableStorage] = None,
record_column: Optional[str] = None,
) -> Iterator[Tuple[Iterable[Tuple[DatasetIdRef,
Optional[StoredDatastoreItemInfo]]],
Set[str]]]:
Optional[Set[str]]]]:
# Docstring inherited from DatastoreRegistryBridge

if records_table is None:
raise ValueError("This implementation requires a records table.")

if not isinstance(records_table, ByNameOpaqueTableStorage):
raise ValueError(f"Records table must support hidden attributes. Got {type(records_table)}.")
assert isinstance(records_table, ByNameOpaqueTableStorage),\
f"Records table must support hidden attributes. Got {type(records_table)}."

if record_class is None:
raise ValueError("Record class must be provided if records table is given.")

# Helper closure to generate the common join+where clause.
def join_records(select: sqlalchemy.sql.Select, location_table: sqlalchemy.schema.Table
) -> sqlalchemy.sql.FromClause:
# mypy needs to be sure
assert isinstance(records_table, ByNameOpaqueTableStorage)
return select.select_from(
records_table._table.join(
location_table,
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/interfaces/_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def emptyTrash(self, records_table: Optional[OpaqueTableStorage] = None,
record_class: Optional[Type[StoredDatastoreItemInfo]] = None,
record_column: Optional[str] = None,
) -> ContextManager[Tuple[Iterable[Tuple[DatasetIdRef,
Optional[StoredDatastoreItemInfo]]],
Set[str]]]:
Optional[StoredDatastoreItemInfo]]],
Optional[Set[str]]]]:
"""Retrieve all the dataset ref IDs that are in the trash
associated for this datastore, and then remove them if the context
exists without an exception being raised.
Expand Down

0 comments on commit 81635cf

Please sign in to comment.