diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 09:57:46 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 09:57:46 -0400 |
| commit | 3b796ff25876e84c636baea33329bd3c43867de6 (patch) | |
| tree | 8284474d4002817760965c480b022aa43eac778d /config_file/config_file_path.py | |
| parent | Drop support for python 3.6, 3.7, and 3.8 (diff) | |
| download | config-file-3b796ff25876e84c636baea33329bd3c43867de6.zip | |
Update dependencies and linting
Diffstat (limited to 'config_file/config_file_path.py')
| -rw-r--r-- | config_file/config_file_path.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/config_file/config_file_path.py b/config_file/config_file_path.py index e4f3ef7..439acee 100644 --- a/config_file/config_file_path.py +++ b/config_file/config_file_path.py @@ -1,5 +1,8 @@ +from __future__ import annotations + import os import pathlib +from typing import Type from config_file.parsers.abstract_parser import AbstractParser from config_file.parsers.ini_parser import IniParser @@ -9,12 +12,16 @@ from config_file.parsers.yaml_parser import YamlParser from .utils import split_on_dot +# NOTE: Python 3.12+ supports subclassing pathlib.Path directly. +# See https://discuss.python.org/t/support-subclassing-pathlib-path/29095 +_BasePath: Type[pathlib.Path] if os.name == "nt": - base = pathlib.WindowsPath + _BasePath = pathlib.WindowsPath else: - base = pathlib.PosixPath + _BasePath = pathlib.PosixPath + -class ConfigFilePath(base): +class ConfigFilePath(_BasePath): # type: ignore[valid-type, misc] """A ConfigFilePath object, which subclasses Path. It provides us easy ways to grab the original config file @@ -23,7 +30,7 @@ class ConfigFilePath(base): """ @property - def original_path(self) -> "ConfigFilePath": + def original_path(self) -> ConfigFilePath: """Computes the original configuration file path. e.g. ConfigFilePath("./config.ini").original_path -> "./config.original.ini" @@ -89,7 +96,7 @@ class ConfigFilePath(base): with open(self, "r") as file: return file.read() - def validate(self) -> "ConfigFilePath": + def validate(self) -> ConfigFilePath: """Validates that the current path exists, is a directory, and expands any home tidles. |