Skip to content

Commit

Permalink
Merge pull request galaxyproject#17299 from mvdbeek/improve_model_man…
Browse files Browse the repository at this point in the history
…ager_typing

Improve ModelManager type hints
  • Loading branch information
jmchilton authored Jan 15, 2024
2 parents 122b19a + 2677a13 commit 344a34f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/galaxy/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,14 @@ def _apply_orm_limit_offset(self, query: Query, limit: Optional[int], offset: Op
return query

# .... query resolution
def one(self, **kwargs) -> Query:
def one(self, **kwargs) -> U:
"""
Sends kwargs to build the query and returns one and only one model.
"""
query = self.query(**kwargs)
return self._one_with_recast_errors(query)

def _one_with_recast_errors(self, query: Query) -> Query:
def _one_with_recast_errors(self, query: Query) -> U:
"""
Call sqlalchemy's one and recast errors to serializable errors if any.
Expand All @@ -323,7 +323,7 @@ def _one_with_recast_errors(self, query: Query) -> Query:
raise exceptions.InconsistentDatabase(f"found more than one {self.model_class.__name__}")

# NOTE: at this layer, all ids are expected to be decoded and in int form
def by_id(self, id: int) -> Query:
def by_id(self, id: int) -> U:
"""
Gets a model by primary id.
"""
Expand Down Expand Up @@ -353,7 +353,7 @@ def list(self, filters=None, order_by=None, limit=None, offset=None, **kwargs):
items = self._apply_fn_filters_gen(items, fn_filters)
return list(self._apply_fn_limit_offset_gen(items, limit, offset))

def count(self, filters=None, **kwargs):
def count(self, filters=None, **kwargs) -> int:
"""
Returns the number of objects matching the given filters.
Expand Down Expand Up @@ -403,7 +403,7 @@ def _split_filters(self, filters):
orm_filters.append(filter_.filter)
return (orm_filters, fn_filters)

def _orm_list(self, query=None, **kwargs):
def _orm_list(self, query: Optional[Query] = None, **kwargs) -> List[U]:
"""
Sends kwargs to build the query return all models found.
"""
Expand Down Expand Up @@ -494,13 +494,13 @@ def create(self, flush: bool = True, *args: Any, **kwargs: Any) -> U:
session.commit()
return item

def copy(self, item, **kwargs):
def copy(self, item, **kwargs) -> U:
"""
Clone or copy an item.
"""
raise exceptions.NotImplemented("Abstract method")

def update(self, item, new_values, flush=True, **kwargs):
def update(self, item, new_values, flush=True, **kwargs) -> U:
"""
Given a dictionary of new values, update `item` and return it.
Expand Down

0 comments on commit 344a34f

Please sign in to comment.