aboutsummaryrefslogtreecommitdiffstats
path: root/config_file
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-08-16 09:57:46 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-08-16 09:57:46 -0400
commit3b796ff25876e84c636baea33329bd3c43867de6 (patch)
tree8284474d4002817760965c480b022aa43eac778d /config_file
parentDrop support for python 3.6, 3.7, and 3.8 (diff)
downloadconfig-file-3b796ff25876e84c636baea33329bd3c43867de6.zip
Update dependencies and linting
Diffstat (limited to 'config_file')
-rw-r--r--config_file/config_file_path.py17
-rw-r--r--config_file/parsers/parse_value.py11
2 files changed, 16 insertions, 12 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.
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):