From b6909256a587a049cc1600718bced660b9ce2cdb Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Mon, 4 Nov 2024 09:28:46 -0800 Subject: [PATCH] chore: make a couple more things frozen/hashable (#307) Manifest and Fpath were not marked with the decorator to make frozen dataclasses, so were unhashable in Python. This adds the decorator to make them hashable. - [x] I ran `make setup && make` to update the generated code after editing a `.atd` file (TODO: have a CI check) - [x] I made sure we're still backward compatible with old versions of the CLI. For example, the Semgrep backend need to still be able to *consume* data generated by Semgrep 1.17.0. See https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades Co-authored-by: Yoann Padioleau --- semgrep_output_v1.atd | 5 +++-- semgrep_output_v1.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index 8a928a8..154da13 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -71,7 +71,7 @@ type raw_json = abstract (*****************************************************************************) (* File path. less: could convert directly to Path class of pathlib library for Python *) -type fpath = string wrap +type fpath = string wrap type uri = string wrap @@ -1856,7 +1856,8 @@ type manifest_kind (* pyproject.toml - https://packaging.python.org/en/latest/guides/writing-pyproject-toml/ *) ] -type manifest = { +type manifest + = { kind: manifest_kind; path: fpath; } diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index 07b5d77..6078d5a 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -281,7 +281,7 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) -@dataclass +@dataclass(frozen=True) class Fpath: """Original type: fpath""" @@ -6885,7 +6885,7 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) -@dataclass +@dataclass(frozen=True) class Manifest: """Original type: manifest = { ... }"""