Skip to content

Commit 0634620

Browse files
committed
Revert "fix: avoid Python 3.9 dataclass unsafe_hash inheritance error"
This reverts commit 62162d2. Thats was not the problem. --- Current issue: ``` tests/test_cli_args.py:8: in <module> import schema_salad.main as cli_parser schema_salad/main.py:16: in <module> ??? schema_salad/codegen.py:18: in <module> ??? schema_salad/rust_codegen.py:266: in <module> ??? E AttributeError: attribute '__dict__' of 'type' objects is not writable ```
1 parent 62162d2 commit 0634620

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

schema_salad/rust_codegen.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,12 @@ class RustMeta(ABC):
175175
pass
176176

177177

178-
@dataclass # ASSERT: Immutable class
178+
@dataclass(unsafe_hash=True) # ASSERT: Immutable class
179179
class RustAttribute:
180180
"""Represents a Rust attribute (e.g., `#[derive(Debug)]`)."""
181181

182182
meta: RustMeta
183183

184-
def __hash__(self) -> int:
185-
return hash(self.meta)
186-
187184
def __str__(self) -> str:
188185
return f"#[{str(self.meta)}]"
189186

@@ -196,16 +193,13 @@ def __str__(self) -> str:
196193
RustGenericsMut = MutableSequence[Union[RustLifetime, "RustPath"]] # alias
197194

198195

199-
@dataclass # ASSERT: Immutable class
196+
@dataclass(unsafe_hash=True) # ASSERT: Immutable class
200197
class RustPathSegment:
201198
"""Represents a segment in a Rust path with optional generics."""
202199

203200
ident: RustIdent
204201
generics: RustGenerics = dataclasses.field(default_factory=tuple)
205202

206-
def __hash__(self) -> int:
207-
return hash((self.ident, self.generics))
208-
209203
REX: ClassVar[Pattern[str]] = re.compile(
210204
r"^([a-zA-Z_]\w*)(?:<([ \w\t,'<>]+)>)?$"
211205
) # Using `re.Pattern[str]` raise CI build errors
@@ -262,17 +256,14 @@ def parse_generics_string(value_generics: str) -> RustGenerics:
262256
RustPathSegmentsMut = MutableSequence[RustPathSegment] # alias
263257

264258

265-
@dataclass # ASSERT: Immutable class
259+
@dataclass(unsafe_hash=True) # ASSERT: Immutable class
266260
class RustPath(RustMeta):
267261
"""Represents a complete Rust path (e.g., `::std::vec::Vec<T>`)."""
268262

269263
# ASSERT: Never initialized with an empty sequence
270264
segments: RustPathSegments
271265
leading_colon: bool = False
272266

273-
def __hash__(self) -> int:
274-
return hash((self.segments, self.leading_colon))
275-
276267
def __truediv__(self, other: Union["RustPath", RustPathSegment]) -> "RustPath":
277268
if self.segments[-1].generics:
278269
raise ValueError("Cannot chain to a RustPath with generics.")
@@ -313,16 +304,13 @@ def from_str(cls, value: str) -> "RustPath":
313304
return cls(segments=tuple(segments), leading_colon=leading_colon)
314305

315306

316-
@dataclass # ASSERT: Immutable class
307+
@dataclass(unsafe_hash=True) # ASSERT: Immutable class
317308
class RustTypeTuple(RustType):
318309
"""Represents a Rust tuple type (e.g., `(T, U)`)."""
319310

320311
# ASSERT: Never initialized with an empty sequence
321312
types: Sequence[RustPath]
322313

323-
def __hash__(self) -> int:
324-
return hash(self.types)
325-
326314
def __str__(self) -> str:
327315
types_str = ", ".join(str(ty) for ty in self.types)
328316
return f"({types_str})"

0 commit comments

Comments
 (0)