Skip to content

Commit

Permalink
Merge pull request galaxyproject#15185 from jmchilton/typathon_types_1
Browse files Browse the repository at this point in the history
Small mypy improvements.
  • Loading branch information
jmchilton authored Dec 12, 2022
2 parents 1d6e57b + 350899b commit c90e1e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
21 changes: 17 additions & 4 deletions lib/galaxy/security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
Galaxy Security
"""
from typing import (
List,
Optional,
)

from typing_extensions import Literal

from galaxy.util.bunch import Bunch

ActionModel = Literal["grant", "restrict"]


class Action:
def __init__(self, action, description, model):
action: str
description: str
model: ActionModel

def __init__(self, action: str, description: str, model: ActionModel):
self.action = action
self.description = description
self.model = model
Expand Down Expand Up @@ -42,14 +55,14 @@ class RBACAgent:
),
)

def get_action(self, name, default=None):
def get_action(self, name: str, default: Optional[Action] = None) -> Optional[Action]:
"""Get a permitted action by its dict key or action name"""
for k, v in self.permitted_actions.items():
if k == name or v.action == name:
return v
return default

def get_actions(self):
def get_actions(self) -> List[Action]:
"""Get all permitted actions as a list of Action objects"""
return list(self.permitted_actions.__dict__.values())

Expand Down Expand Up @@ -165,5 +178,5 @@ def get_permitted_actions(filter=None):
if filter is None:
return RBACAgent.permitted_actions
tmp_bunch = Bunch()
[tmp_bunch.__dict__.__setitem__(k, v) for k, v in RBACAgent.permitted_actions.items() if k.startswith(filter)]
[tmp_bunch.dict().__setitem__(k, v) for k, v in RBACAgent.permitted_actions.items() if k.startswith(filter)]
return tmp_bunch
4 changes: 3 additions & 1 deletion lib/galaxy/tool_util/verify/asserts/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def _extract_from_tar(bytes, fn):
# so make this consistent for tar
if ti.isdir():
return ""
with tar_temp.extractfile(fn) as member_fh:
tar_file = tar_temp.extractfile(fn)
assert tar_file is not None
with tar_file as member_fh:
return member_fh.read()


Expand Down
4 changes: 0 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ check_untyped_defs = False
check_untyped_defs = False
[mypy-galaxy.tools.bundled.data_source.microbial_import_code]
check_untyped_defs = False
[mypy-galaxy.security]
check_untyped_defs = False
[mypy-galaxy.datatypes.converters.pileup_to_interval_index_converter]
check_untyped_defs = False
[mypy-galaxy.datatypes.converters.bgzip]
Expand Down Expand Up @@ -111,8 +109,6 @@ check_untyped_defs = False
check_untyped_defs = False
[mypy-galaxy.tools.bundled.filters.random_lines_two_pass]
check_untyped_defs = False
[mypy-galaxy.tool_util.verify.asserts.archive]
check_untyped_defs = False
[mypy-galaxy.tool_util.deps.brew_exts]
check_untyped_defs = False
[mypy-galaxy.model.item_attrs]
Expand Down
5 changes: 5 additions & 0 deletions test/unit/data/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ def test_get_uuid():

rval = model.get_uuid()
assert isinstance(rval, UUID)


def test_permitted_actions():
actions = model.Dataset.permitted_actions
assert actions and len(actions.values()) == 2

0 comments on commit c90e1e3

Please sign in to comment.