From 5789ecb0e4009495aa18b9134ad757ff942ae239 Mon Sep 17 00:00:00 2001 From: Dom Batten Date: Thu, 2 Oct 2025 09:24:01 +0100 Subject: [PATCH] Rename `types.py` module This clashes with a built-in `types` module so need to rename it. --- src/maison/config.py | 8 ++++---- src/maison/config_parser.py | 6 +++--- src/maison/config_validator.py | 6 +++--- src/maison/parsers/ini.py | 4 ++-- src/maison/parsers/pyproject.py | 4 ++-- src/maison/parsers/toml.py | 4 ++-- src/maison/protocols.py | 12 ++++++------ src/maison/service.py | 10 +++++----- src/maison/{types.py => typedefs.py} | 0 src/maison/utils.py | 6 +++--- tests/integration_tests/test_config.py | 6 +++--- tests/unit_tests/test_config_reader.py | 6 +++--- tests/unit_tests/test_config_validator.py | 4 ++-- tests/unit_tests/test_service.py | 10 +++++----- tests/unit_tests/test_utils.py | 12 ++++++------ 15 files changed, 49 insertions(+), 49 deletions(-) rename src/maison/{types.py => typedefs.py} (100%) diff --git a/src/maison/config.py b/src/maison/config.py index 05156f1..70853be 100644 --- a/src/maison/config.py +++ b/src/maison/config.py @@ -10,7 +10,7 @@ from maison import parsers from maison import protocols from maison import service -from maison import types +from maison import typedefs def _bootstrap_service(package_name: str) -> service.ConfigService: @@ -83,7 +83,7 @@ def __str__(self) -> str: return f"" @property - def values(self) -> types.ConfigValues: + def values(self) -> typedefs.ConfigValues: """Return the user's configuration values. Returns: @@ -92,7 +92,7 @@ def values(self) -> types.ConfigValues: return self._values @values.setter - def values(self, values: types.ConfigValues) -> None: + def values(self, values: typedefs.ConfigValues) -> None: """Set the user's configuration values.""" self._values = values @@ -145,7 +145,7 @@ def validate( self, schema: typing.Optional[type[protocols.IsSchema]] = None, use_schema_values: bool = True, - ) -> types.ConfigValues: + ) -> typedefs.ConfigValues: """Validate the configuration. Warning: diff --git a/src/maison/config_parser.py b/src/maison/config_parser.py index d93b647..cec66d4 100644 --- a/src/maison/config_parser.py +++ b/src/maison/config_parser.py @@ -4,7 +4,7 @@ import typing from maison import errors -from maison import types +from maison import typedefs ParserDictKey = tuple[str, typing.Union[str, None]] @@ -13,7 +13,7 @@ class Parser(typing.Protocol): """Defines the interface for a `Parser` class that's used to parse a config.""" - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """Parse a config file. Args: @@ -42,7 +42,7 @@ def register_parser( key = (suffix, stem) self._parsers[key] = parser - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """See `Parser.parse_config`.""" key: ParserDictKey diff --git a/src/maison/config_validator.py b/src/maison/config_validator.py index e16e862..696122c 100644 --- a/src/maison/config_validator.py +++ b/src/maison/config_validator.py @@ -1,7 +1,7 @@ """Holds the tools for validating a user's config.""" from maison import protocols -from maison import types +from maison import typedefs class Validator: @@ -11,8 +11,8 @@ class Validator: """ def validate( - self, values: types.ConfigValues, schema: type[protocols.IsSchema] - ) -> types.ConfigValues: + self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema] + ) -> typedefs.ConfigValues: """See `Validator.validate`.""" validated_schema = schema(**values) return validated_schema.model_dump() diff --git a/src/maison/parsers/ini.py b/src/maison/parsers/ini.py index ac03fd0..c621fe7 100644 --- a/src/maison/parsers/ini.py +++ b/src/maison/parsers/ini.py @@ -3,7 +3,7 @@ import configparser import pathlib -from maison import types +from maison import typedefs class IniParser: @@ -12,7 +12,7 @@ class IniParser: Implements the `Parser` protocol """ - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """See the Parser.parse_config method.""" config = configparser.ConfigParser() _ = config.read(file_path) diff --git a/src/maison/parsers/pyproject.py b/src/maison/parsers/pyproject.py index 3f7d5a4..a8cee06 100644 --- a/src/maison/parsers/pyproject.py +++ b/src/maison/parsers/pyproject.py @@ -4,7 +4,7 @@ import toml -from maison import types +from maison import typedefs class PyprojectParser: @@ -22,7 +22,7 @@ def __init__(self, package_name: str) -> None: """ self._package_name = package_name - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """See the Parser.parse_config method.""" try: pyproject_dict = dict(toml.load(file_path)) diff --git a/src/maison/parsers/toml.py b/src/maison/parsers/toml.py index a040f4d..e21b9ef 100644 --- a/src/maison/parsers/toml.py +++ b/src/maison/parsers/toml.py @@ -4,7 +4,7 @@ import toml -from maison import types +from maison import typedefs class TomlParser: @@ -13,7 +13,7 @@ class TomlParser: Implements the `Parser` protocol """ - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """See the Parser.parse_config method.""" try: return dict(toml.load(file_path)) diff --git a/src/maison/protocols.py b/src/maison/protocols.py index af51f62..b708e39 100644 --- a/src/maison/protocols.py +++ b/src/maison/protocols.py @@ -3,13 +3,13 @@ import pathlib import typing -from maison import types +from maison import typedefs class Parser(typing.Protocol): """Defines the interface for a parser used to parse a config file.""" - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """Parses a config file. Args: @@ -24,7 +24,7 @@ def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: class IsSchema(typing.Protocol): """Protocol for config schemas.""" - def model_dump(self) -> types.ConfigValues: + def model_dump(self) -> typedefs.ConfigValues: """Convert the validated config to a dict.""" ... @@ -49,7 +49,7 @@ def get_file_path( class ConfigParser(typing.Protocol): """Defines the interface for a class that parses a config.""" - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: """Parse a config. Args: @@ -65,8 +65,8 @@ class Validator(typing.Protocol): """Defines the interface for a class that validates some config values.""" def validate( - self, values: types.ConfigValues, schema: type[IsSchema] - ) -> types.ConfigValues: + self, values: typedefs.ConfigValues, schema: type[IsSchema] + ) -> typedefs.ConfigValues: """Validate a config. Args: diff --git a/src/maison/service.py b/src/maison/service.py index e1ac14f..10e17c9 100644 --- a/src/maison/service.py +++ b/src/maison/service.py @@ -5,7 +5,7 @@ from collections.abc import Iterable from maison import protocols -from maison import types +from maison import typedefs from maison import utils @@ -53,7 +53,7 @@ def get_config_values( self, config_file_paths: Iterable[pathlib.Path], merge_configs: bool, - ) -> types.ConfigValues: + ) -> typedefs.ConfigValues: """Get the values from config files. Args: @@ -64,7 +64,7 @@ def get_config_values( Returns: The values from the config file(s) """ - config_values: types.ConfigValues = {} + config_values: typedefs.ConfigValues = {} for path in config_file_paths: parsed_config = self.config_parser.parse_config(path) @@ -76,8 +76,8 @@ def get_config_values( return config_values def validate_config( - self, values: types.ConfigValues, schema: type[protocols.IsSchema] - ) -> types.ConfigValues: + self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema] + ) -> typedefs.ConfigValues: """Validate config values against a schema. Args: diff --git a/src/maison/types.py b/src/maison/typedefs.py similarity index 100% rename from src/maison/types.py rename to src/maison/typedefs.py diff --git a/src/maison/utils.py b/src/maison/utils.py index 3a9b9e2..30f2543 100644 --- a/src/maison/utils.py +++ b/src/maison/utils.py @@ -1,11 +1,11 @@ """Module to hold various utils.""" -from maison import types +from maison import typedefs def deep_merge( - destination: types.ConfigValues, source: types.ConfigValues -) -> types.ConfigValues: + destination: typedefs.ConfigValues, source: typedefs.ConfigValues +) -> typedefs.ConfigValues: """Recursively updates the destination dictionary. Usage example: diff --git a/tests/integration_tests/test_config.py b/tests/integration_tests/test_config.py index d5811d0..2d7b2f4 100644 --- a/tests/integration_tests/test_config.py +++ b/tests/integration_tests/test_config.py @@ -5,7 +5,7 @@ from maison import config from maison import errors -from maison import types +from maison import typedefs class TestUserConfig: @@ -99,7 +99,7 @@ class Schema: def __init__(self, *args: object, **kwargs: object) -> None: pass - def model_dump(self) -> types.ConfigValues: + def model_dump(self) -> typedefs.ConfigValues: return {"key": "validated"} cfg = config.UserConfig( @@ -123,7 +123,7 @@ class Schema: def __init__(self, *args: object, **kwargs: object) -> None: pass - def model_dump(self) -> types.ConfigValues: + def model_dump(self) -> typedefs.ConfigValues: return {"key": "validated"} cfg = config.UserConfig( diff --git a/tests/unit_tests/test_config_reader.py b/tests/unit_tests/test_config_reader.py index ca86597..338e976 100644 --- a/tests/unit_tests/test_config_reader.py +++ b/tests/unit_tests/test_config_reader.py @@ -4,16 +4,16 @@ from maison import config_parser from maison import errors -from maison import types +from maison import typedefs class FakePyprojectParser: - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: return {"config": "pyproject"} class FakeTomlParser: - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: return {"config": "toml"} diff --git a/tests/unit_tests/test_config_validator.py b/tests/unit_tests/test_config_validator.py index 60eac32..4e39c03 100644 --- a/tests/unit_tests/test_config_validator.py +++ b/tests/unit_tests/test_config_validator.py @@ -1,12 +1,12 @@ from maison import config_validator -from maison import types +from maison import typedefs class Schema: def __init__(self, *args: object, **kwargs: object) -> None: pass - def model_dump(self) -> types.ConfigValues: + def model_dump(self) -> typedefs.ConfigValues: return {"key": "validated"} diff --git a/tests/unit_tests/test_service.py b/tests/unit_tests/test_service.py index 4500382..674a540 100644 --- a/tests/unit_tests/test_service.py +++ b/tests/unit_tests/test_service.py @@ -3,7 +3,7 @@ from maison import protocols from maison import service as config_service -from maison import types +from maison import typedefs class FakeFileSystem: @@ -16,21 +16,21 @@ def get_file_path( class FakeConfigParser: - def parse_config(self, file_path: pathlib.Path) -> types.ConfigValues: + def parse_config(self, file_path: pathlib.Path) -> typedefs.ConfigValues: return { "values": {file_path.stem: file_path.suffix}, } class Schema: - def model_dump(self) -> types.ConfigValues: + def model_dump(self) -> typedefs.ConfigValues: return {"key": "validated"} class FakeValidator: def validate( - self, values: types.ConfigValues, schema: type[protocols.IsSchema] - ) -> types.ConfigValues: + self, values: typedefs.ConfigValues, schema: type[protocols.IsSchema] + ) -> typedefs.ConfigValues: return schema().model_dump() diff --git a/tests/unit_tests/test_utils.py b/tests/unit_tests/test_utils.py index 80d95aa..6c59df0 100644 --- a/tests/unit_tests/test_utils.py +++ b/tests/unit_tests/test_utils.py @@ -2,7 +2,7 @@ import pytest -from maison import types +from maison import typedefs from maison.utils import deep_merge @@ -28,17 +28,17 @@ class TestDeepMerge: ) def test_success( self, - a: types.ConfigValues, - b: types.ConfigValues, - expected: types.ConfigValues, + a: typedefs.ConfigValues, + b: typedefs.ConfigValues, + expected: typedefs.ConfigValues, ) -> None: assert deep_merge(a, b) == expected assert a == expected def test_incompatible_dicts(self) -> None: """Trying to merge incompatible dicts returns an error""" - dict_a: types.ConfigValues = {"1": "2", "2": "5"} - dict_b: types.ConfigValues = {"1": {"3": "4"}} + dict_a: typedefs.ConfigValues = {"1": "2", "2": "5"} + dict_b: typedefs.ConfigValues = {"1": {"3": "4"}} with pytest.raises(RuntimeError): _ = deep_merge(dict_a, dict_b)