forked from Mirror/pmbootstrap
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:
parent
459d5a6ac4
commit
eaaa7091ff
1 changed files with 11 additions and 2 deletions
|
@ -4,6 +4,8 @@
|
||||||
"""Global runtime context"""
|
"""Global runtime context"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import overload, Literal
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,8 +44,15 @@ class Context:
|
||||||
__context: Context
|
__context: Context
|
||||||
|
|
||||||
|
|
||||||
# mypy: disable-error-code="return-value"
|
@overload
|
||||||
def get_context(allow_failure: bool = False) -> Context:
|
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."""
|
"""Get immutable global runtime context."""
|
||||||
global __context
|
global __context
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue