diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 08:43:11 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2025-08-16 08:43:11 -0400 |
| commit | 837b9b8f8ba4c395ea6379ac243adcd7a5ac4c92 (patch) | |
| tree | 8d367b1f0cfb2c29060d0a312be9f0aa32590c7e | |
| parent | Remove -x for run tests (diff) | |
| download | config-file-837b9b8f8ba4c395ea6379ac243adcd7a5ac4c92.zip | |
Fix config file path subclasses in 3.13
| -rw-r--r-- | config_file/config_file.py | 2 | ||||
| -rw-r--r-- | config_file/config_file_path.py | 11 | ||||
| -rw-r--r-- | tests/conftest.py | 12 | ||||
| -rw-r--r-- | tests/test_config_file_path.py | 4 |
4 files changed, 16 insertions, 13 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py index 079c903..b5083ff 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -24,7 +24,7 @@ class ConfigFile: ParsingError: If the file_path could not be parsed. """ self.__path = ConfigFilePath(file_path).validate() - self.__parser = self.__path.parser + self.__parser = self.__path.file_parser @property def path(self) -> Path: diff --git a/config_file/config_file_path.py b/config_file/config_file_path.py index 1daad7b..e4f3ef7 100644 --- a/config_file/config_file_path.py +++ b/config_file/config_file_path.py @@ -1,6 +1,5 @@ import os -from pathlib import Path -from typing import Type +import pathlib from config_file.parsers.abstract_parser import AbstractParser from config_file.parsers.ini_parser import IniParser @@ -10,8 +9,12 @@ from config_file.parsers.yaml_parser import YamlParser from .utils import split_on_dot +if os.name == "nt": + base = pathlib.WindowsPath +else: + base = pathlib.PosixPath -class ConfigFilePath(type(Path())): +class ConfigFilePath(base): """A ConfigFilePath object, which subclasses Path. It provides us easy ways to grab the original config file @@ -47,7 +50,7 @@ class ConfigFilePath(type(Path())): return extension[1:] @property - def parser(self) -> Type[AbstractParser]: + def file_parser(self) -> AbstractParser: """Determine what parser should be used for this file. Raises: diff --git a/tests/conftest.py b/tests/conftest.py index 9392368..81f2c0b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Callable, Tuple, Type, Union +from typing import Callable, Tuple, Union import pytest @@ -90,7 +90,7 @@ def template_original_file() -> Callable[[Path], Path]: @pytest.fixture def template_and_parser( template_file: Callable[[str, str], Path] -) -> Callable[[str, str], Tuple[Path, Type[AbstractParser]]]: +) -> Callable[[str, str], Tuple[Path, AbstractParser]]: """ Retrieve the parser and test template for a particular supported file type. @@ -107,15 +107,15 @@ def template_and_parser( def func( file_type: str, template_name: str = "default" - ) -> Tuple[Path, Type[AbstractParser]]: + ) -> Tuple[Path, AbstractParser]: test_file = template_file(file_type, template_name) - return test_file, ConfigFilePath(test_file).parser + return test_file, ConfigFilePath(test_file).file_parser return func @pytest.fixture -def templated_parser(template_and_parser) -> Callable[[str, str], Type[AbstractParser]]: +def templated_parser(template_and_parser) -> Callable[[str, str], AbstractParser]: """ Retrieve a parser for a particular supported file type with a test template already read into it. Small helper around @@ -131,7 +131,7 @@ def templated_parser(template_and_parser) -> Callable[[str, str], Type[AbstractP read in. """ - def func(file_type: str, template_name: str = "default") -> Type[AbstractParser]: + def func(file_type: str, template_name: str = "default") -> AbstractParser: return template_and_parser(file_type, template_name)[1] return func diff --git a/tests/test_config_file_path.py b/tests/test_config_file_path.py index 30b3b7f..e5ec5ba 100644 --- a/tests/test_config_file_path.py +++ b/tests/test_config_file_path.py @@ -79,7 +79,7 @@ def test_config_file_path_decides_on_the_correct_parser( template = template_file(template_file_type, "default") path = ConfigFilePath(template) - assert isinstance(path.parser, expected_parser_type) + assert isinstance(path.file_parser, expected_parser_type) @pytest.mark.parametrize("filename", ["some-file", "some-file.unsupported-extension"]) @@ -94,4 +94,4 @@ def test_config_file_path_raises_value_error_on_parser_if_invalid_extension(file path = ConfigFilePath(filename) with pytest.raises(ValueError): - path.parser + path.file_parser |