From 43feb8f5268fff8bc566bc7b8972ef77e424aa8e Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:32:26 +0200 Subject: [PATCH] FIX: only update pyright settings if `tool.pyright` --- src/repoma/check_dev_files/pyright.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/repoma/check_dev_files/pyright.py b/src/repoma/check_dev_files/pyright.py index cbe0f077..6262d99b 100644 --- a/src/repoma/check_dev_files/pyright.py +++ b/src/repoma/check_dev_files/pyright.py @@ -1,6 +1,7 @@ """Check and update :code:`mypy` settings.""" import json import os +from typing import TYPE_CHECKING, Optional from repoma.errors import PrecommitError from repoma.utilities import CONFIG_PATH @@ -13,6 +14,9 @@ write_pyproject, ) +if TYPE_CHECKING: + from tomlkit.items import Table + def main() -> None: executor = Executor() @@ -41,12 +45,14 @@ def _merge_config_into_pyproject() -> None: def _update_settings() -> None: pyproject = load_pyproject() - settings = get_sub_table(pyproject, "tool.pyright", create=True) + pyright_settings: Optional[Table] = pyproject.get("tool", {}).get("pyright") + if pyright_settings is None: + return minimal_settings = { "typeCheckingMode": "strict", } - if not complies_with_subset(settings, minimal_settings): - settings.update(minimal_settings) + if not complies_with_subset(pyright_settings, minimal_settings): + pyright_settings.update(minimal_settings) write_pyproject(pyproject) msg = f"Updated pyright configuration in {CONFIG_PATH.pyproject}" raise PrecommitError(msg)