diff --git a/config/linux.py b/config/linux.py index 3eee4c93..5d543d3f 100644 --- a/config/linux.py +++ b/config/linux.py @@ -3,7 +3,6 @@ import os import pathlib import sys from configparser import ConfigParser -from typing import Any, List, Optional, Union from config import AbstractConfig, appname, logger @@ -18,7 +17,7 @@ class LinuxConfig(AbstractConfig): __unescape_lut = {'\\': '\\', 'n': '\n', ';': ';', 'r': '\r', '#': '#'} __escape_lut = {'\\': '\\', '\n': 'n', ';': ';', '\r': 'r'} - def __init__(self, filename: Optional[str] = None) -> None: + def __init__(self, filename: str | None = None) -> None: super().__init__() # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() @@ -42,7 +41,7 @@ class LinuxConfig(AbstractConfig): self.filename.parent.mkdir(exist_ok=True, parents=True) - self.config: Optional[ConfigParser] = ConfigParser(comment_prefixes=('#',), interpolation=None) + self.config: ConfigParser | None = ConfigParser(comment_prefixes=('#',), interpolation=None) self.config.read(self.filename) # read() ignores files that dont exist # Ensure that our section exists. This is here because configparser will happily create files for us, but it @@ -85,7 +84,7 @@ class LinuxConfig(AbstractConfig): :param s: str - The string to unescape. :return: str - The unescaped string. """ - out: List[str] = [] + out: list[str] = [] i = 0 while i < len(s): c = s[i] @@ -107,7 +106,7 @@ class LinuxConfig(AbstractConfig): return "".join(out) - def __raw_get(self, key: str) -> Optional[str]: + def __raw_get(self, key: str) -> str | None: """ Get a raw data value from the config file. @@ -183,7 +182,7 @@ class LinuxConfig(AbstractConfig): return bool(int(data)) - def set(self, key: str, val: Union[int, str, List[str]]) -> None: + def set(self, key: str, val: int | str | list[str]) -> None: """ Set the given key's data to the given value. @@ -192,7 +191,7 @@ class LinuxConfig(AbstractConfig): if self.config is None: raise ValueError('attempt to use a closed config') - to_set: Optional[str] = None + to_set: str | None = None if isinstance(val, bool): to_set = str(int(val))