Skip to content

Commit

Permalink
Cleanup typing - rebase into paired/unpaired...
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jan 20, 2025
1 parent 3d42bd0 commit b5afde6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class TestCollectionDefElementInternal(TypedDict):
class XmlTestCollectionDefDict(TypedDict):
model_class: Literal["TestCollectionDef"]
attributes: TestCollectionAttributeDict
collection_type: CollectionType
collection_type: Optional[CollectionType]
fields: Optional[List[FieldDict]]
elements: List[TestCollectionDefElementDict]
name: str
Expand Down
27 changes: 22 additions & 5 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,15 +2020,23 @@ def do_validate(v):
raise ValueError(f"At most {self.max} datasets are required for {self.name}")


def src_id_to_item(
sa_session: "Session", value: typing.MutableMapping[str, Any], security: "IdEncodingHelper"
) -> Union[
ItemFromSrcAny = Union[
DatasetCollectionElement,
HistoryDatasetAssociation,
HistoryDatasetCollectionAssociation,
LibraryDatasetDatasetAssociation,
CollectionAdapter,
]:
]
ItemFromSrcCollection = Union[
DatasetCollectionElement,
HistoryDatasetCollectionAssociation,
CollectionAdapter,
]


def src_id_to_item(
sa_session: "Session", value: typing.MutableMapping[str, Any], security: "IdEncodingHelper"
) -> ItemFromSrcAny:
adapter_model = None
if value["src"] == "CollectionAdapter":
adapter_model = validate_collection_adapter_src_dict(value)
Expand Down Expand Up @@ -2064,6 +2072,15 @@ def src_id_to_item(
return item


def src_id_to_item_collection(
sa_session: "Session", value: typing.MutableMapping[str, Any], security: "IdEncodingHelper"
) -> ItemFromSrcCollection:
rval = src_id_to_item(sa_session, value, security)
if isinstance(rval, (LibraryDatasetDatasetAssociation, HistoryDatasetAssociation)):
raise ValueError("Expected to find collection, but got single dataset wrapper")
return cast(ItemFromSrcCollection, rval)


class DataToolParameter(BaseDataToolParameter):
# TODO, Nate: Make sure the following unit tests appropriately test the dataset security
# components. Add as many additional tests as necessary.
Expand Down Expand Up @@ -2491,7 +2508,7 @@ def from_json(self, value, trans, other_values=None):
session = trans.sa_session

other_values = other_values or {}
rval: Optional[Union[DatasetCollectionElement, HistoryDatasetCollectionAssociation, CollectionAdapter]] = None
rval: Optional[ItemFromSrcCollection] = None
if trans.workflow_building_mode is workflow_building_modes.ENABLED:
return None
if not value and not self.optional and not self.default_object:
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/tools/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def has_single_item(self) -> bool:
return self.__input_supplied and len(self.__element_instance_list) == 1

@property
def single_item(self) -> "DatasetCollectionElementWrapper":
def single_item(self) -> Optional["DatasetCollectionElementWrapper"]:
return self[0]

@property
Expand Down

0 comments on commit b5afde6

Please sign in to comment.