From 0f5e897d2684416f0c35245d36129ee898e6430c Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 2 May 2023 14:55:29 +0100 Subject: [PATCH] Make mypy execution more reproducible Related: https://github.com/python/mypy/issues/12664 Related: https://github.com/python/mypy/issues/8823 --- .config/requirements-test.txt | 1 + .pre-commit-config.yaml | 8 +++++--- pyproject.toml | 2 ++ src/ansiblelint/config.py | 2 +- src/ansiblelint/yaml_utils.py | 6 +++--- test/test_yaml_utils.py | 6 +++--- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.config/requirements-test.txt b/.config/requirements-test.txt index 58c8feb8f4..95ca8d49a8 100644 --- a/.config/requirements-test.txt +++ b/.config/requirements-test.txt @@ -10,6 +10,7 @@ pytest >= 7.2.2 pytest-mock pytest-plus >= 0.2 # for PYTEST_REQPASS pytest-xdist >= 2.1.0 +ruamel-yaml-clib # needed for mypy spdx-tools >= 0.7.1 # Apache types-jsonschema # IDE support types-pyyaml # IDE support diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a126830c8a..b736fad9c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -125,7 +125,7 @@ repos: types: [file, yaml] entry: yamllint --strict - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.263" + rev: "v0.0.264" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -148,7 +148,8 @@ repos: - jinja2 - pytest>=7.2.2 - rich>=13.2.0 - - ruamel.yaml + - ruamel-yaml>=0.17.22 + - ruamel-yaml-clib>=0.2.7 - spdx-tools - subprocess-tee - types-PyYAML @@ -177,7 +178,8 @@ repos: - pytest>=7.2.2 - pyyaml - rich>=13.2.0 - - ruamel.yaml + - ruamel-yaml>=0.17.22 + - ruamel-yaml-clib>=0.2.7 - spdx-tools - typing_extensions - wcmatch diff --git a/pyproject.toml b/pyproject.toml index eb0d30f146..a5c15db73f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,6 +107,8 @@ disallow_any_generics = true # warn_unused_configs = True # site-packages is here to help vscode mypy integration getting confused exclude = "(build|dist|test/local-content|site-packages|~/.pyenv|examples/playbooks/collections|plugins/modules)" +# https://github.com/python/mypy/issues/12664 +no_incremental = true [[tool.mypy.overrides]] module = [ diff --git a/src/ansiblelint/config.py b/src/ansiblelint/config.py index bfca5154c5..e41ec9b350 100644 --- a/src/ansiblelint/config.py +++ b/src/ansiblelint/config.py @@ -106,7 +106,7 @@ class Options: # pylint: disable=too-many-instance-attributes,too-few-public-me cache_dir: Path | None = None colored: bool = True configured: bool = False - cwd: Path = Path(".") # noqa: RUF009 + cwd: Path = Path(".") display_relative_path: bool = True exclude_paths: list[str] = field(default_factory=list) format: str = "brief" # noqa: A003 diff --git a/src/ansiblelint/yaml_utils.py b/src/ansiblelint/yaml_utils.py index c804c883f4..82f94e1aab 100644 --- a/src/ansiblelint/yaml_utils.py +++ b/src/ansiblelint/yaml_utils.py @@ -808,9 +808,9 @@ def __init__( self.compact_seq_map = True # type: ignore[assignment] # key after dash # Do not use yaml.indent() as it obscures the purpose of these vars: - self.map_indent = 2 # type: ignore[assignment] - self.sequence_indent = 4 if indent_sequences else 2 # type: ignore[assignment] - self.sequence_dash_offset = self.sequence_indent - 2 # type: ignore[operator] + self.map_indent = 2 + self.sequence_indent = 4 if indent_sequences else 2 + self.sequence_dash_offset = self.sequence_indent - 2 # If someone doesn't want our FormattedEmitter, they can change it. self.Emitter = FormattedEmitter diff --git a/test/test_yaml_utils.py b/test/test_yaml_utils.py index 8d131337d1..3b2669cd0a 100644 --- a/test/test_yaml_utils.py +++ b/test/test_yaml_utils.py @@ -189,9 +189,9 @@ def test_custom_ruamel_yaml_emitter( """Test ``ruamel.yaml.YAML.dump()`` sequence formatting and quotes.""" yaml = YAML(typ="rt") # NB: ruamel.yaml does not have typehints, so mypy complains about everything here. - yaml.explicit_start = True # type: ignore[assignment] - yaml.map_indent = map_indent # type: ignore[assignment] - yaml.sequence_indent = sequence_indent # type: ignore[assignment] + yaml.explicit_start = True + yaml.map_indent = map_indent + yaml.sequence_indent = sequence_indent yaml.sequence_dash_offset = sequence_dash_offset if alternate_emitter is not None: yaml.Emitter = alternate_emitter