Skip to content

Commit

Permalink
Improve type annotation of SharedModelMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Feb 21, 2025
1 parent c96a538 commit 20ddd49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/galaxy/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Dict,
List,
Type,
TYPE_CHECKING,
Union,
)

Expand All @@ -28,6 +29,20 @@

from galaxy.util.bunch import Bunch

if TYPE_CHECKING:
from galaxy.model import (
APIKeys as GalaxyAPIKeys,
GalaxySession as GalaxyGalaxySession,
PasswordResetToken as GalaxyPasswordResetToken,
User as GalaxyUser,
)
from tool_shed.webapp.model import (
APIKeys as ToolShedAPIKeys,
GalaxySession as ToolShedGalaxySession,
PasswordResetToken as ToolShedPasswordResetToken,
User as ToolShedUser,
)

log = logging.getLogger(__name__)

# Create a ContextVar with mutable state, this allows sync tasks in the context
Expand Down Expand Up @@ -128,10 +143,10 @@ class SharedModelMapping(ModelMapping):
a way to do app.model.<CLASS> for common code shared by the tool shed and Galaxy.
"""

User: Type
GalaxySession: Type
APIKeys: Type
PasswordResetToken: Type
User: Union[Type["GalaxyUser"], Type["ToolShedUser"]]
GalaxySession: Union[Type["GalaxyGalaxySession"], Type["ToolShedGalaxySession"]]
APIKeys: Union[Type["GalaxyAPIKeys"], Type["ToolShedAPIKeys"]]
PasswordResetToken: Union[Type["GalaxyPasswordResetToken"], Type["ToolShedPasswordResetToken"]]


def versioned_objects(iter):
Expand Down
3 changes: 3 additions & 0 deletions lib/galaxy/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from threading import local
from typing import (
Optional,
Type,
TYPE_CHECKING,
)

Expand All @@ -17,6 +18,7 @@
from galaxy.model.triggers.update_audit_table import install as install_timestamp_triggers

if TYPE_CHECKING:
from galaxy.model import User as GalaxyUser
from galaxy.objectstore import BaseObjectStore

log = logging.getLogger(__name__)
Expand All @@ -25,6 +27,7 @@


class GalaxyModelMapping(SharedModelMapping):
User: Type["GalaxyUser"]
security_agent: GalaxyRBACAgent
thread_local_log: Optional[local]

Expand Down
6 changes: 6 additions & 0 deletions lib/tool_shed/webapp/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Any,
Dict,
Optional,
Type,
TYPE_CHECKING,
)

import tool_shed.webapp.model
Expand All @@ -17,12 +19,16 @@
from tool_shed.webapp.model import mapper_registry
from tool_shed.webapp.security import CommunityRBACAgent

if TYPE_CHECKING:
from tool_shed.webapp.model import User as ToolShedUser

log = logging.getLogger(__name__)

metadata = mapper_registry.metadata


class ToolShedModelMapping(SharedModelMapping):
User: Type["ToolShedUser"]
security_agent: CommunityRBACAgent
shed_counter: shed_statistics.ShedCounter
create_tables: bool
Expand Down

0 comments on commit 20ddd49

Please sign in to comment.