Skip to content

Commit

Permalink
Fix type annotation for digestTables.
Browse files Browse the repository at this point in the history
We were using += on the results of these calls, which only works for
lists or tuples, not general iterables (and it was always lists at
runtime).

Not sure why MyPy didn't complain; maybe it doesn't check arithmetic
operators?
  • Loading branch information
TallJimbo committed Jan 5, 2023
1 parent 432b91c commit 100a12c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/dimensions/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__all__ = ["CachingDimensionRecordStorage"]

from collections.abc import Iterable, Mapping
from collections.abc import Mapping
from typing import Any

import sqlalchemy
Expand Down Expand Up @@ -159,6 +159,6 @@ def get_record_cache(self, context: queries.SqlQueryContext) -> Mapping[DataCoor
self._cache = cache
return self._cache

def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
# Docstring inherited from DimensionRecordStorage.digestTables.
return self._nested.digestTables()
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/dimensions/governor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__all__ = ["BasicGovernorDimensionRecordStorage"]

from collections.abc import Callable, Iterable, Mapping
from collections.abc import Callable, Mapping
from typing import Any, cast

import sqlalchemy
Expand Down Expand Up @@ -176,6 +176,6 @@ def get_record_cache(self, context: queries.SqlQueryContext) -> Mapping[DataCoor
self._cache = cache
return cast(Mapping[DataCoordinate, DimensionRecord], self._cache)

def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
# Docstring inherited from DimensionRecordStorage.digestTables.
return [self._table]
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/dimensions/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__all__ = ["QueryDimensionRecordStorage"]

from collections.abc import Iterable, Mapping
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any

import sqlalchemy
Expand Down Expand Up @@ -144,6 +144,6 @@ def fetch_one(self, data_id: DataCoordinate, context: queries.SqlQueryContext) -
# nothing to actually fetch: everything we need is in the data ID.
return self.element.RecordClass(**data_id.byName())

def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
# Docstring inherited from DimensionRecordStorage.digestTables.
return []
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/dimensions/skypix.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__all__ = ["BasicSkyPixDimensionRecordStorage"]

from typing import TYPE_CHECKING, Iterable
from typing import TYPE_CHECKING

import sqlalchemy
from lsst.daf.relation import Calculation, ColumnExpression, Join, Relation
Expand Down Expand Up @@ -101,6 +101,6 @@ def fetch_one(self, data_id: DataCoordinate, context: queries.SqlQueryContext) -
index = data_id[self._dimension.name]
return self._dimension.RecordClass(id=index, region=self._dimension.pixelization.pixel(index))

def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
# Docstring inherited from DimensionRecordStorage.digestTables.
return []
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/registry/dimensions/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import dataclasses
import logging
from collections.abc import Iterable, Mapping, Sequence, Set
from collections.abc import Mapping, Sequence, Set
from typing import Any

import sqlalchemy
Expand Down Expand Up @@ -209,7 +209,7 @@ def sync(self, record: DimensionRecord, update: bool = False) -> bool | dict[str
# We updated something other than a region.
return inserted_or_updated

def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
# Docstring inherited from DimensionRecordStorage.digestTables.
result = [self._table]
if self._skypix_overlap_tables is not None:
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/daf/butler/registry/interfaces/_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ def get_record_cache(
return None

@abstractmethod
def digestTables(self) -> Iterable[sqlalchemy.schema.Table]:
def digestTables(self) -> list[sqlalchemy.schema.Table]:
"""Return tables used for schema digest.
Returns
-------
tables : `Iterable` [ `sqlalchemy.schema.Table` ]
Possibly empty set of tables for schema digest calculations.
tables : `list` [ `sqlalchemy.schema.Table` ]
Possibly empty list of tables for schema digest calculations.
"""
raise NotImplementedError()

Expand Down

0 comments on commit 100a12c

Please sign in to comment.