Skip to content

Commit 096096a

Browse files
authored
feat: add get_app class method to Application (#48)
* feat: add get_app * test: add test
1 parent 6f34971 commit 096096a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/app_model/_app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import contextlib
4-
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Tuple, Type
4+
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Optional, Tuple, Type
55

66
import in_n_out as ino
77
from psygnal import Signal
@@ -122,6 +122,11 @@ def get_or_create(cls, name: str) -> Application:
122122
"""Get app named `name` or create and return a new one if it doesn't exist."""
123123
return cls._instances[name] if name in cls._instances else cls(name)
124124

125+
@classmethod
126+
def get_app(cls, name: str) -> Optional[Application]:
127+
"""Return app named `name` or None if it doesn't exist."""
128+
return cls._instances.get(name)
129+
125130
@classmethod
126131
def destroy(cls, name: str) -> None:
127132
"""Destroy the `Application` named `name`.

tests/test_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313

1414
def test_app_create():
15+
assert Application.get_app("my_app") is None
1516
app = Application("my_app")
17+
assert Application.get_app("my_app") is app
1618

1719
# NOTE: for some strange reason, this test fails if I move this line
1820
# below the error assertion below... I don't know why.

0 commit comments

Comments
 (0)