pmb.core.context: Properly type get_context()

Instead of just disabling the return-value error code, actually type it
properly using overloads.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2614
This commit is contained in:
Newbyte 2025-06-03 11:46:44 +02:00 committed by Oliver Smith
parent 459d5a6ac4
commit eaaa7091ff
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -4,6 +4,8 @@
"""Global runtime context"""
from pathlib import Path
from typing import overload, Literal
from .config import Config
@ -42,8 +44,15 @@ class Context:
__context: Context
# mypy: disable-error-code="return-value"
def get_context(allow_failure: bool = False) -> Context:
@overload
def get_context(allow_failure: Literal[False] = ...) -> Context: ...
@overload
def get_context(allow_failure: Literal[True] = ...) -> Context | None: ...
def get_context(allow_failure: bool = False) -> Context | None:
"""Get immutable global runtime context."""
global __context