pmb: Use inspect.get_annotations()

On Python 3.10 and newer, this is the recommended way of accessing
annotations[1]. It also works with Mypyc, unlike directly accessing
__annotations__.

 [1]: https://docs.python.org/3/howto/annotations.html

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2634
This commit is contained in:
Newbyte 2025-07-01 12:47:18 +02:00 committed by Oliver Smith
parent 53f050ef14
commit 0ade6cab4d
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 6 additions and 4 deletions

View file

@ -5,6 +5,7 @@ from pathlib import Path
from pmb.core.context import get_context
from pmb.core.arch import Arch
from pmb.helpers import logging
import inspect
import os
import pmb.config
import pmb.helpers.other
@ -53,7 +54,7 @@ def _parse_kernel_suffix(info: dict[str, str], device: str, kernel: str | None)
ret = copy.copy(info)
suffix_kernel = kernel.replace("-", "_")
for key in Deviceinfo.__annotations__.keys():
for key in inspect.get_annotations(Deviceinfo).keys():
key_kernel = f"{key}_{suffix_kernel}"
if key_kernel not in ret:
continue