Skip to content

Commit

Permalink
Add type annotations - PR to dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Sep 17, 2024
1 parent 66a5705 commit 48ba9f0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 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 @@ -363,7 +363,7 @@ def parse_python_template_version(self) -> Optional[packaging.version.Version]:
Return minimum python version that the tool template has been developed against.
"""

def parse_cores_min(self):
def parse_cores_min(self) -> Union[float, int, str]:
"""Return minimum number of cores required to run this tool."""
return 1

Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,11 @@ def __init__(
config_file,
tool_source: ToolSource,
app: "UniverseApplication",
guid=None,
guid: Optional[str] = None,
repository_id=None,
tool_shed_repository=None,
allow_code_files=True,
dynamic=False,
dynamic: bool = False,
tool_dir=None,
):
"""Load a tool from the config named by `config_file`"""
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def allow_user_access(self, user, attempting_access=True):
return False
return True

def parse(self, tool_source: ToolSource, guid=None, dynamic=False):
def parse(self, tool_source: ToolSource, guid: Optional[str] = None, dynamic: bool = False) -> None:
"""
Read tool configuration from the element `root` and fill in `self`.
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tools/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def __init__(
self.collection_info = collection_info
self.completed_jobs = completed_jobs

self._on_text = None
self._on_text: Optional[str] = None

# Populated as we go...
self.failed_jobs = 0
Expand Down Expand Up @@ -322,7 +322,7 @@ def record_error(self, error):
self.execution_errors.append(error)

@property
def on_text(self):
def on_text(self) -> Optional[str]:
collection_info = self.collection_info
if self._on_text is None and collection_info is not None:
if not collection_info.uses_ephemeral_collections:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/tools/execution_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import logging
from typing import Collection

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,7 +48,7 @@ def filter_output(tool, output, incoming):
return False


def on_text_for_names(input_names):
def on_text_for_names(input_names: Collection[str]) -> str:
# input_names may contain duplicates... this is because the first value in
# multiple input dataset parameters will appear twice once as param_name
# and once as param_name1.
Expand Down
30 changes: 15 additions & 15 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def get_label(self):
"""Return user friendly name for the parameter"""
return self.label if self.label else self.name

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
"""
Convert a value from an HTML POST into the parameters preferred value
format.
Expand Down Expand Up @@ -472,7 +472,7 @@ def __init__(self, tool, input_source):
if self.min is not None or self.max is not None:
self.validators.append(validation.InRangeValidator(None, self.min, self.max))

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
other_values = other_values or {}
try:
return int(value)
Expand Down Expand Up @@ -545,7 +545,7 @@ def __init__(self, tool, input_source):
if self.min is not None or self.max is not None:
self.validators.append(validation.InRangeValidator(None, self.min, self.max))

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
other_values = other_values or {}
try:
return float(value)
Expand Down Expand Up @@ -591,11 +591,11 @@ class BooleanToolParameter(ToolParameter):
>>> print(p.name)
_name
>>> assert sorted(p.to_dict(trans).items()) == [('argument', None), ('falsevalue', '_falsevalue'), ('help', ''), ('hidden', False), ('is_dynamic', False), ('label', ''), ('model_class', 'BooleanToolParameter'), ('name', '_name'), ('optional', False), ('refresh_on_change', False), ('truevalue', '_truevalue'), ('type', 'boolean'), ('value', True)]
>>> print(p.from_json('true'))
>>> print(p.from_json('true', trans))
True
>>> print(p.to_param_dict_string(True))
_truevalue
>>> print(p.from_json('false'))
>>> print(p.from_json('false', trans))
False
>>> print(p.to_param_dict_string(False))
_falsevalue
Expand All @@ -619,7 +619,7 @@ def __init__(self, tool, input_source):
self.optional = input_source.get_bool("optional", False)
self.checked = boolean_is_checked(input_source)

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
return self.to_python(value)

def to_python(self, value, app=None):
Expand Down Expand Up @@ -670,7 +670,7 @@ class FileToolParameter(ToolParameter):
def __init__(self, tool, input_source):
super().__init__(tool, input_source)

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
# Middleware or proxies may encode files in special ways (TODO: this
# should be pluggable)
if isinstance(value, FilesPayload):
Expand Down Expand Up @@ -769,7 +769,7 @@ def to_param_dict_string(self, value, other_values=None):
else:
return lst[0]

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
return self.to_python(value, trans.app, validate=True)

def to_json(self, value, app, use_security):
Expand Down Expand Up @@ -889,7 +889,7 @@ def __init__(self, tool, input_source):
def get_initial_value(self, trans, other_values):
return self._get_value(trans)

def from_json(self, value=None, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
return self._get_value(trans)

def _get_value(self, trans):
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def get_legal_names(self, trans, other_values):
"""
return {n: v for n, v, _ in self.get_options(trans, other_values)}

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
return self._select_from_json(value, trans, other_values=other_values, require_legal_value=True)

def _select_from_json(self, value, trans, other_values=None, require_legal_value=True):
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def __init__(self, tool, input_source):
self.default_value = input_source.get("value", None)
self.is_dynamic = True

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
other_values = other_values or {}
if self.multiple:
tag_list = []
Expand Down Expand Up @@ -1416,7 +1416,7 @@ def to_json(self, value, app, use_security):
return value.strip()
return value

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
"""
Label convention prepends column number with a 'c', but tool uses the integer. This
removes the 'c' when entered into a workflow.
Expand Down Expand Up @@ -1704,7 +1704,7 @@ def recurse_options(legal_values, options):
recurse_options(legal_values, self.get_options(trans=trans, other_values=other_values))
return legal_values

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
other_values = other_values or {}
legal_values = self.get_legal_values(trans, other_values, value)
if not legal_values and trans.workflow_building_mode:
Expand Down Expand Up @@ -2111,7 +2111,7 @@ def __init__(self, tool, input_source, trans=None):
)
self.conversions.append((name, conv_extension, [conv_type]))

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
session = trans.sa_session

other_values = other_values or {}
Expand Down Expand Up @@ -2468,7 +2468,7 @@ def match_multirun_collections(self, trans, history, dataset_collection_matcher)
if match:
yield history_dataset_collection, match.implicit_conversion

def from_json(self, value, trans=None, other_values=None):
def from_json(self, value, trans, other_values=None):
session = trans.sa_session

other_values = other_values or {}
Expand Down

0 comments on commit 48ba9f0

Please sign in to comment.