From 3b796ff25876e84c636baea33329bd3c43867de6 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 16 Aug 2025 09:57:46 -0400 Subject: Update dependencies and linting --- config_file/config_file_path.py | 17 ++++++++++++----- config_file/parsers/parse_value.py | 11 ++++------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'config_file') 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. diff --git a/config_file/parsers/parse_value.py b/config_file/parsers/parse_value.py index 2009585..58d8864 100644 --- a/config_file/parsers/parse_value.py +++ b/config_file/parsers/parse_value.py @@ -1,4 +1,5 @@ """This module allows you to parse a string into its native type.""" + import ast import re from typing import Any @@ -30,19 +31,15 @@ def parse_value(value: Any) -> Any: passed in value. """ if isinstance(value, dict): - parsed = {} - + parsed_map = {} for item in value: - parsed[item] = parse_value(value[item]) - - return parsed + parsed_map[item] = parse_value(value[item]) + return parsed_map if isinstance(value, list): parsed = [] - for item in value: parsed.append(parse_value(item)) - return parsed if can_be_parsed_as_int(value): -- cgit v1.2.3