Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add get_app class method to Application #48

Merged
merged 2 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app_model/_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import contextlib
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Tuple, Type
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, List, Optional, Tuple, Type

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

@classmethod
def get_app(cls, name: str) -> Optional[Application]:
"""Return app named `name` or None if it doesn't exist."""
return cls._instances.get(name)

@classmethod
def destroy(cls, name: str) -> None:
"""Destroy the `Application` named `name`.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@


def test_app_create():
assert Application.get_app("my_app") is None
app = Application("my_app")
assert Application.get_app("my_app") is app

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