From 86b7e1f2972e373c87cc06f31109b668a675ec92 Mon Sep 17 00:00:00 2001 From: phalberg Date: Sun, 11 Oct 2026 20:19:25 +0200 Subject: [PATCH 1/7] chore: add return types for validator_class --- tests/unit_test/test_validator_class.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index ca6cfc7..046a89f 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -32,7 +32,7 @@ def helper_sig_def(name_def): return params, sig -def test_sig_context(): +def test_sig_context() -> None: val_context_sig = helper_sig_class(name_class=validator.ValidationContext) @@ -52,7 +52,7 @@ def test_sig_context(): ], ids=["Signature without order", "Signature with order"], ) -def test_sig_walk_n_order(name_def): +def test_sig_walk_n_order(name_def) -> None: walk_n_order_sig, sig = helper_sig_def(name_def=name_def) @@ -76,7 +76,7 @@ def test_sig_walk_n_order(name_def): "check signature for accepting new values", ], ) -def test_accept_new_value_and_keys(name_def): +def test_accept_new_value_and_keys(name_def) -> None: accept_new, sig = helper_sig_def(name_def) sig_list_keys = ["current_key", "new_key", "context"] From 8b6c9c388b324a345de2b42546cde6776d301026 Mon Sep 17 00:00:00 2001 From: phalberg Date: Sun, 11 Oct 2026 21:17:45 +0200 Subject: [PATCH 2/7] chore: simplify imports --- tests/unit_test/test_validator_class.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 046a89f..4bf54be 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -3,12 +3,6 @@ import pytest from cfglock import validator -from cfglock.validator import ( - accept_new_keys, - accept_new_value, - walk_yaml_in_order, - walk_yaml_with_no_order, -) def helper_sig_class(name_class): @@ -47,8 +41,8 @@ def test_sig_context() -> None: @pytest.mark.parametrize( "name_def", [ - walk_yaml_with_no_order, - walk_yaml_in_order, + validator.walk_yaml_with_no_order, + validator.walk_yaml_in_order, ], ids=["Signature without order", "Signature with order"], ) @@ -68,8 +62,8 @@ def test_sig_walk_n_order(name_def) -> None: @pytest.mark.parametrize( "name_def", [ - accept_new_keys, - accept_new_value, + validator.accept_new_keys, + validator.accept_new_value, ], ids=[ "check signature of accepting new keys", From 9f4d6453a7e0d6e1fe261bb03f014efc317e08fd Mon Sep 17 00:00:00 2001 From: phalberg Date: Mon, 12 Oct 2026 08:01:18 +0200 Subject: [PATCH 3/7] chore: remove old usage of inspect --- tests/unit_test/test_validator_class.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 4bf54be..4929e9b 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -2,6 +2,8 @@ import pytest +from typing import get_type_hints + from cfglock import validator @@ -10,9 +12,7 @@ def helper_sig_class(name_class): Retrive the signature of a class. """ - sig = inspect.getfullargspec(name_class).annotations - - return sig + return get_type_hints(name_class) def helper_sig_def(name_def): @@ -29,10 +29,8 @@ def helper_sig_def(name_def): def test_sig_context() -> None: val_context_sig = helper_sig_class(name_class=validator.ValidationContext) - sig_list = ["new_path", "current_path", "order_matters"] - assert ("return", None) in val_context_sig.items() assert all(key in val_context_sig for key in sig_list) assert ("new_path", str) in val_context_sig.items() assert ("current_path", str) in val_context_sig.items() From d0a843e412cfe3ba5173598ef3af30414db5c730 Mon Sep 17 00:00:00 2001 From: phalberg Date: Wed, 14 Oct 2026 15:58:08 +0200 Subject: [PATCH 4/7] chore: add some basic annotations --- src/cfglock/helper.py.save | 186 ++++++++++++++++++++++++ src/cfglock/validator.py | 4 +- tests/integration_test/test_sync.py | 6 +- tests/unit_test/test_sync_command.py | 4 +- tests/unit_test/test_validator_class.py | 8 +- 5 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 src/cfglock/helper.py.save diff --git a/src/cfglock/helper.py.save b/src/cfglock/helper.py.save new file mode 100644 index 0000000..d4defe4 --- /dev/null +++ b/src/cfglock/helper.py.save @@ -0,0 +1,186 @@ +import filecmp +import json +import os +from abc import ABC, abstractmethod +from pathlib import Path +from typing import ClassVar, Any +from collections.abc import Mapping + +import typer +import yaml +from dotenv import load_dotenv + +from cfglock.validator import ( + ConfigLockError, + ValidationContext, + keys_to_ignore, + walk_yaml_in_order, + walk_yaml_with_no_order, +) + +load_dotenv() +CONFIG_LOG_FILE_PATH: str = os.environ.get("CONFIG_LOG_FILE_PATH", "config.lock.json") + +# TODO: remove typer.echo at some point! + + +type MappingValue = dict[str, Any] + + +class FileReader[T: Mapping[str, Any]](ABC): + @abstractmethod + def read(self, file_path: str) -> T: + """Reads the appropriate file.""" + pass + + +class YamlReader(FileReader[MappingValue]): + def read(self, file_path: str) -> MappingValue: + # TODO: i belive thsi can also return back a list with no dict actually... + with open(file_path, "r") as f: + data = yaml.safe_load(f) or {} + + if not isinstance(data, dict): + raise TypeError( + f"Expected YAML object/dict in {file_path}, got {type(data).__name__}" + ) + typer.echo("Successfully read file") + return data + + +class JsonReader(FileReader[MappingValue]): + def read(self, file_path: str) -> MappingValue: + with open(file_path, "r") as f: + data = json.load(f) or {} + + if not isinstance(data, dict): + raise TypeError( + f"Expected JSON in {file_path}, got {type(data).__name__}" + ) + + typer.echo("Successfully read file") + return data + + +class FileReaderFactory: + reader: ClassVar[dict[str, FileReader[MappingValue]]] = { + ".yaml": YamlReader(), + ".yml": YamlReader(), + ".json": JsonReader(), + } + + @classmethod + def load(cls, file_path: str) -> MappingValue: + """Loads the relevant filetype. + args + file_path(str): str representation of file path. + returns + a dictionary with the contents of the file + """ + + path = Path(file_path) + suffix = path.suffix.lower() + + reader = cls.reader.get(suffix) + + if not reader: + typer.echo( + f"File not suppported: {suffix}. Use .yaml, .yml, or .json.", + err=True, + ) + raise ValueError("Error not able to read the file") + + typer.echo(f"Reading {file_path}...") + return reader.read(file_path) + + +def check_file_identicality( + file_path: str, config_file_path: str = CONFIG_LOG_FILE_PATH +) -> bool: + """Checks if files are identical, if they are it returns True, False otherwise""" + try: + a = FileReaderFactory.load(file_path) + b = FileReaderFactory.load(config_file_path) + + # metadata we do not care about + if isinstance(a, dict): + a = {k: v for k, v in a.items() if k not in keys_to_ignore} + if isinstance(b, dict): + b = {k: v for k, v in b.items() if k not in keys_to_ignore} + + if a == b: + return True + filecmp.clear_cache() + res = filecmp.cmp(file_path, config_file_path, shallow=False) + return res + except OSError: + filecmp.clear_cache() + res = filecmp.cmp(file_path, config_file_path, shallow=False) + return res + + +def check_file_exists(file_path: str | None = None) -> bool: + if file_path is None: + file_path = CONFIG_LOG_FILE_PATH + + path_parent = Path(file_path).parent + path = path_parent / CONFIG_LOG_FILE_PATH + exists = path.exists() + if not exists: + typer.echo(f"The path does not exist: {path}") + return exists + + +def write_json(data: MappingValue, file_path: str | None = None) -> None: + data.update({"version": 1}) + if file_path is None: + file_path = CONFIG_LOG_FILE_PATH + parent_path = Path(file_path) + new_path = parent_path / CONFIG_LOG_FILE_PATH + try: + with open(new_path, "w") as json_file: + json.dump(data, json_file, indent=4) + except TypeError as exc: + raise TypeError(f"Data could not be serialized to JSON: {exc}") from exc + except OSError as exc: + raise OSError(f"Could not write JSON file at {file_path}: {exc}") from exc + else: + typer.echo("Successfully wrote file") + + +def check_compatibility( + new_file_path: str, + curr_file_path: str | None = None, + *, + order_matters: bool = False, +) -> None: + """ "" + Check compatiblity for two files given the file paths + 1) Keys must be same as previous keys, and order_matters can determine if the order also matters + 2) Values must have the same types as previously + 3) Adding new entries is allowed + 4) Deleting entries is not allowed + """ + # the lock file + current_file_path = None + if curr_file_path is None: + current_file_path = Path(CONFIG_LOG_FILE_PATH) + else: + parent_new = Path(new_file_path).parent + current_file_path = parent_new / "config.lock.json" + context = ValidationContext( + new_path=new_file_path, + current_path=current_file_path, + order_matters=order_matters, + ) + new_data = FileReaderFactory.load(new_file_path) + + try: + current_data = FileReaderFactory.load(current_file_path) + except FileNotFoundError: + raise ConfigLockError("lock file was not found, please use init") + + if order_matters: + walk_yaml_in_order(current_data, new_data, context) + else: + walk_yaml_with_no_order(current_data, new_data, context) diff --git a/src/cfglock/validator.py b/src/cfglock/validator.py index 81b8626..d9802e9 100644 --- a/src/cfglock/validator.py +++ b/src/cfglock/validator.py @@ -131,7 +131,9 @@ def accept_new_keys( ) -def accept_new_value(current_value, new_value, context: ValidationContext) -> None: +def accept_new_value[T]( + current_value: T, new_value: T, context: ValidationContext +) -> None: """ General logic for accepting new values: 1) the type of the new_value cannot be different than the type of the current_value diff --git a/tests/integration_test/test_sync.py b/tests/integration_test/test_sync.py index f65cb89..63a1630 100644 --- a/tests/integration_test/test_sync.py +++ b/tests/integration_test/test_sync.py @@ -6,7 +6,7 @@ from cfglock.validator import ConfigLockError -def test_sync_correct(runner_with_lock_file_setup, fixture_dir): +def test_sync_correct(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "config.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -27,7 +27,7 @@ def test_sync_correct(runner_with_lock_file_setup, fixture_dir): assert not output["app_settings"]["maintenance_mode"] -def test_sync_outdated_source_file(runner_with_lock_file_setup, fixture_dir): +def test_sync_outdated_source_file(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "configbreak_namechange.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -43,7 +43,7 @@ def test_sync_outdated_source_file(runner_with_lock_file_setup, fixture_dir): assert "lock file is outdated" in str(result.exception).lower() -def test_sync_outdated_lock_file(runner_with_lock_file_setup, fixture_dir): +def test_sync_outdated_lock_file(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "config.yaml" with open("config.lock.json", "w", encoding="utf-8") as f: diff --git a/tests/unit_test/test_sync_command.py b/tests/unit_test/test_sync_command.py index 3ee5475..c045951 100644 --- a/tests/unit_test/test_sync_command.py +++ b/tests/unit_test/test_sync_command.py @@ -2,7 +2,7 @@ from cfglock.validator import ConfigLockError -def test_check_file_identicality(runner_with_lock_file_setup): +def test_check_file_identicality(runner_with_lock_file_setup) -> None: # write YAML that matches the repository fixture `tests/test_files/config.yaml` with open("config.yaml", "w", encoding="utf-8") as f: f.write("version: 1\n\n") @@ -15,7 +15,7 @@ def test_check_file_identicality(runner_with_lock_file_setup): assert result.exception is None -def test_outdated_lock_file(runner_with_lock_file_setup): +def test_outdated_lock_file(runner_with_lock_file_setup) -> None: with open("config.yaml", "w", encoding="utf-8") as f: f.write("name: example") diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 4929e9b..0507027 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -2,12 +2,12 @@ import pytest -from typing import get_type_hints +from typing import get_type_hints, Any from cfglock import validator -def helper_sig_class(name_class): +def helper_sig_class(name_class: validator.ValidationContext) -> dict[str, Any]: """ Retrive the signature of a class. """ @@ -23,6 +23,10 @@ def helper_sig_def(name_def): params = sig.parameters.items() + print("EXAMPLE", helper_sig_class(name_def)) + print("SIG", sig) + print("PARAMS", params) + return params, sig From 7eac09d942ec1ee0471fc3335419368a059df95d Mon Sep 17 00:00:00 2001 From: phalberg Date: Wed, 14 Oct 2026 16:12:47 +0200 Subject: [PATCH 5/7] chore: fix basic missing type annotations for tests --- src/cfglock/docs_server.py | 2 +- src/cfglock/validator.py | 6 +++--- tests/integration_test/test_init.py | 2 +- tests/integration_test/test_lock.py | 16 ++++++++-------- tests/unit_test/test_lock_command.py | 16 ++++++++-------- tests/unit_test/test_validator_class.py | 1 + 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/cfglock/docs_server.py b/src/cfglock/docs_server.py index 9835463..8a08e0d 100644 --- a/src/cfglock/docs_server.py +++ b/src/cfglock/docs_server.py @@ -26,7 +26,7 @@ waitForReload(); """ -# TODO: refactor this file at a later stage! +# TODO: refactor this file at a later stage! This file might be removed to be used with something else at some later stage. class ReloadState: diff --git a/src/cfglock/validator.py b/src/cfglock/validator.py index d9802e9..5f4c68b 100644 --- a/src/cfglock/validator.py +++ b/src/cfglock/validator.py @@ -40,14 +40,14 @@ def __init__( actual_value, message="Validation Failed", order_matters=False, - ): + ) -> None: super().__init__(message, error_code=100) self.path = path self.expected_value = expected_value self.actual_value = actual_value self.order_matters = order_matters - def __str__(self): + def __str__(self) -> str: base_msg = f""" In path: {self.path} Expected: {self.expected_value} @@ -139,7 +139,7 @@ def accept_new_value[T]( 1) the type of the new_value cannot be different than the type of the current_value """ - def typed_value(value): + def typed_value(value) -> str: return f"<{type(value).__name__}> with value: {value!r}" if type(current_value) is not type(new_value): diff --git a/tests/integration_test/test_init.py b/tests/integration_test/test_init.py index 6fd81f9..7e6f4ef 100644 --- a/tests/integration_test/test_init.py +++ b/tests/integration_test/test_init.py @@ -5,7 +5,7 @@ from cfglock import cli -def test_init_correct(runner_setup, fixture_dir): +def test_init_correct(runner_setup, fixture_dir) -> None: fixture = fixture_dir / "config.yaml" with open(fixture, "r", encoding="utf-8") as f: diff --git a/tests/integration_test/test_lock.py b/tests/integration_test/test_lock.py index e75a397..0cd95e3 100644 --- a/tests/integration_test/test_lock.py +++ b/tests/integration_test/test_lock.py @@ -6,7 +6,7 @@ from cfglock.validator import ValidationError -def helper_ok(result, output): +def helper_ok(result, output) -> None: print(result.exception) assert result.exit_code == 0 assert output["version"] == 1 @@ -14,12 +14,12 @@ def helper_ok(result, output): assert not output["app_settings"]["maintenance_mode"] -def helper_fail(result, error): +def helper_fail(result, error) -> None: assert result.exit_code == 1 assert isinstance(result.exception, error) -def test_lock_correct(runner_with_lockfile, fixture_dir): +def test_lock_correct(runner_with_lockfile, fixture_dir) -> None: fixture = fixture_dir / "config.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -40,7 +40,7 @@ def test_lock_correct(runner_with_lockfile, fixture_dir): assert "environment" in output["app_settings"] -def test_lock_string_change_ok(runner_with_lock_file_setup, fixture_dir): +def test_lock_string_change_ok(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "config_string_change.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -58,7 +58,7 @@ def test_lock_string_change_ok(runner_with_lock_file_setup, fixture_dir): assert "production" in output["app_settings"]["environment"] -def test_lock_add_on_change_ok(runner_with_lock_file_setup, fixture_dir): +def test_lock_add_on_change_ok(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "config_add_on_change.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -76,7 +76,7 @@ def test_lock_add_on_change_ok(runner_with_lock_file_setup, fixture_dir): assert "ok" in output["app_settings"]["new_entry"] -def test_lock_fail_namechange(runner_with_lock_file_setup, fixture_dir): +def test_lock_fail_namechange(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "configbreak_namechange.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -93,7 +93,7 @@ def test_lock_fail_namechange(runner_with_lock_file_setup, fixture_dir): # assert "found: name_changed" in str(result.exception).lower() TODO: fix this at some point!! -def test_lock_fail_typechange(runner_with_lock_file_setup, fixture_dir): +def test_lock_fail_typechange(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "configbreak_typechange.yaml" with open(fixture, "r", encoding="utf-8") as f: @@ -110,7 +110,7 @@ def test_lock_fail_typechange(runner_with_lock_file_setup, fixture_dir): assert "found: with value: 'false'" in str(result.exception).lower() -def test_lock_fail_orderchange(runner_with_lock_file_setup, fixture_dir): +def test_lock_fail_orderchange(runner_with_lock_file_setup, fixture_dir) -> None: fixture = fixture_dir / "configbreak_orderchange.yaml" with open(fixture, "r", encoding="utf-8") as f: diff --git a/tests/unit_test/test_lock_command.py b/tests/unit_test/test_lock_command.py index b650ae4..88fc074 100644 --- a/tests/unit_test/test_lock_command.py +++ b/tests/unit_test/test_lock_command.py @@ -4,7 +4,7 @@ from cfglock.validator import ConfigLockError, ValidationError -def test_lock_works(runner_with_lock_file_setup): +def test_lock_works(runner_with_lock_file_setup) -> None: with open("config.lock.json", "r") as f: output = json.load(f) @@ -35,7 +35,7 @@ def test_lock_works(runner_with_lock_file_setup): assert output.get("new_entry") == 10 -def test_no_lock_file_available(runner, tmp_path): +def test_no_lock_file_available(runner, tmp_path) -> None: path = tmp_path / "config.json" path.write_text(json.dumps({"name": "example", "object": False})) @@ -58,7 +58,7 @@ def test_no_lock_file_available(runner, tmp_path): assert "lock file was not found" in str(result.exception).lower() -def test_not_available_file(runner): +def test_not_available_file(runner) -> None: result = runner.invoke(cli.app, ["lock", "some_file.json"]) @@ -66,7 +66,7 @@ def test_not_available_file(runner): assert isinstance(result.exception, FileNotFoundError) -def test_compatibility_file(runner_with_lock_file_setup): +def test_compatibility_file(runner_with_lock_file_setup) -> None: with open("incompatible_file.toml", "w", encoding="utf-8") as f: f.write('[section]\nkey = "value"') @@ -80,7 +80,7 @@ def test_compatibility_file(runner_with_lock_file_setup): assert "not able to read" in str(result.exception).lower() -def test_fail_new_key(runner_with_lock_file_setup): +def test_fail_new_key(runner_with_lock_file_setup) -> None: with open("new_file.yaml", "w", encoding="utf-8") as f: f.write("first_name: example") @@ -92,7 +92,7 @@ def test_fail_new_key(runner_with_lock_file_setup): assert all(s in exc_str for s in ["in path", "expected", "found", "error code"]) -def test_fail_new_value(runner_with_lock_file_setup): +def test_fail_new_value(runner_with_lock_file_setup) -> None: # change type for a nested value (environment should be a string) with open("new_file.yaml", "w", encoding="utf-8") as f: f.write("app_settings:\n environment: 12") @@ -115,7 +115,7 @@ def test_fail_new_value(runner_with_lock_file_setup): ) -def test_order_matters_works(runner_with_lock_file_setup): +def test_order_matters_works(runner_with_lock_file_setup) -> None: with open("new_file.yaml", "w", encoding="utf-8") as f: f.write("object: false") @@ -133,7 +133,7 @@ def test_order_matters_works(runner_with_lock_file_setup): ) -def test_no_order_matters_works(runner_with_lock_file_setup): +def test_no_order_matters_works(runner_with_lock_file_setup) -> None: # create YAML with same content but different order with open("new_file.yaml", "w", encoding="utf-8") as f: f.write( diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 0507027..4fa4eba 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -15,6 +15,7 @@ def helper_sig_class(name_class: validator.ValidationContext) -> dict[str, Any]: return get_type_hints(name_class) +# TODO: simplifly the logic for this one perhaps def helper_sig_def(name_def): """ Retrive parameters and signature of a defintion. From fd9425de947e382ffa001bca6a50ad5a94995af7 Mon Sep 17 00:00:00 2001 From: phalberg Date: Wed, 14 Oct 2026 16:53:53 +0200 Subject: [PATCH 6/7] chore: fixup type annotations for paramtrize --- tests/unit_test/test_validator_class.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 4fa4eba..81981d3 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -4,6 +4,7 @@ from typing import get_type_hints, Any +from collections.abc import Callable from cfglock import validator @@ -41,15 +42,16 @@ def test_sig_context() -> None: assert ("current_path", str) in val_context_sig.items() +name_defs: list[Callable] = [ + validator.walk_yaml_with_no_order, + validator.walk_yaml_in_order, +] + + @pytest.mark.parametrize( - "name_def", - [ - validator.walk_yaml_with_no_order, - validator.walk_yaml_in_order, - ], - ids=["Signature without order", "Signature with order"], + "name_def", name_defs, ids=["Signature without order", "Signature with order"] ) -def test_sig_walk_n_order(name_def) -> None: +def test_sig_walk_n_order(name_def: list[Callable]) -> None: walk_n_order_sig, sig = helper_sig_def(name_def=name_def) From 0e36a75cd83ab44bdcec4ac68798b3771b51bc04 Mon Sep 17 00:00:00 2001 From: phalberg Date: Mon, 26 Oct 2026 18:22:52 +0100 Subject: [PATCH 7/7] chore: remove old save file --- tests/unit_test/test_validator_class.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/unit_test/test_validator_class.py b/tests/unit_test/test_validator_class.py index 81981d3..56e4fbd 100644 --- a/tests/unit_test/test_validator_class.py +++ b/tests/unit_test/test_validator_class.py @@ -21,11 +21,12 @@ def helper_sig_def(name_def): """ Retrive parameters and signature of a defintion. """ + # new_sig = get_type_hints(name_def) sig = inspect.signature(name_def) params = sig.parameters.items() - print("EXAMPLE", helper_sig_class(name_def)) + print("EXAMPLE", get_type_hints(name_def)) print("SIG", sig) print("PARAMS", params) @@ -64,12 +65,15 @@ def test_sig_walk_n_order(name_def: list[Callable]) -> None: assert ("context", sig_obj) in dict_walk_n_order.items() +name_defs: list[Callable] = [ + validator.accept_new_keys, + validator.accept_new_value, +] + + @pytest.mark.parametrize( "name_def", - [ - validator.accept_new_keys, - validator.accept_new_value, - ], + name_defs, ids=[ "check signature of accepting new keys", "check signature for accepting new values",