forked from Mirror/pmbootstrap
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:
parent
53f050ef14
commit
0ade6cab4d
2 changed files with 6 additions and 4 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
from copy import deepcopy
|
||||
import enum
|
||||
import inspect
|
||||
import multiprocessing
|
||||
from typing import Any, ClassVar, TypedDict
|
||||
from pathlib import Path
|
||||
|
@ -90,14 +91,14 @@ class Config:
|
|||
|
||||
def __init__(self) -> None:
|
||||
# Make sure we aren't modifying the class defaults
|
||||
for key in Config.__annotations__.keys():
|
||||
for key in inspect.get_annotations(Config).keys():
|
||||
setattr(self, key, deepcopy(Config.get_default(key)))
|
||||
|
||||
@staticmethod
|
||||
def keys() -> list[str]:
|
||||
keys = list(Config.__annotations__.keys())
|
||||
keys = list(inspect.get_annotations(Config).keys())
|
||||
keys.remove("mirrors")
|
||||
keys += [f"mirrors.{k}" for k in Mirrors.__annotations__.keys()]
|
||||
keys += [f"mirrors.{k}" for k in inspect.get_annotations(Mirrors).keys()]
|
||||
return sorted(keys)
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue