diff --git a/projects/jdwp/defs/command_sets/event_request.py b/projects/jdwp/defs/command_sets/event_request.py index 4b661ee..46c4694 100644 --- a/projects/jdwp/defs/command_sets/event_request.py +++ b/projects/jdwp/defs/command_sets/event_request.py @@ -81,20 +81,20 @@ "Modifier cases", TaggedUnion( __SetCommand_out_modKind, - { - ModifierKind.COUNT: CountModifier, - ModifierKind.CONDITIONAL: ConditionalModifier, - ModifierKind.THREAD_ONLY: ThreadOnlyModifier, - ModifierKind.CLASS_ONLY: ClassOnlyModifier, - ModifierKind.CLASS_MATCH: ClassMatchModifier, - ModifierKind.CLASS_EXCLUDE: ClassExcludeModifier, - ModifierKind.STEP: StepModifier, - ModifierKind.LOCATION_ONLY: LocationOnlyModifier, - ModifierKind.EXCEPTION_ONLY: ExceptionOnlyModifier, - ModifierKind.FIELD_ONLY: FieldOnlyModifier, - ModifierKind.INSTANCE_ONLY: InstanceOnlyModifier, - ModifierKind.SOURCE_NAME_MATCH: SourceNameMatchModifier, - }, + [ + (ModifierKind.COUNT, CountModifier), + (ModifierKind.CONDITIONAL, ConditionalModifier), + (ModifierKind.THREAD_ONLY, ThreadOnlyModifier), + (ModifierKind.CLASS_ONLY, ClassOnlyModifier), + (ModifierKind.CLASS_MATCH, ClassMatchModifier), + (ModifierKind.CLASS_EXCLUDE, ClassExcludeModifier), + (ModifierKind.STEP, StepModifier), + (ModifierKind.LOCATION_ONLY, LocationOnlyModifier), + (ModifierKind.EXCEPTION_ONLY, ExceptionOnlyModifier), + (ModifierKind.FIELD_ONLY, FieldOnlyModifier), + (ModifierKind.INSTANCE_ONLY, InstanceOnlyModifier), + (ModifierKind.SOURCE_NAME_MATCH, SourceNameMatchModifier), + ], ), "Modifier cases.", ) diff --git a/projects/jdwp/defs/schema.py b/projects/jdwp/defs/schema.py index 483e6be..2a3c56a 100644 --- a/projects/jdwp/defs/schema.py +++ b/projects/jdwp/defs/schema.py @@ -4,7 +4,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Optional, Generic, TypeVar, Type as TypeAlias, Union +from typing import Optional, Generic, Tuple, TypeVar, Type as TypeAlias, Union from collections.abc import Mapping from enum import Enum from collections.abc import Set, Sequence @@ -85,7 +85,10 @@ class TaggedUnion(Generic[EnumT]): """Tagged Union class type""" tag: Field[UnionTag[EnumT]] - cases: Mapping[EnumT, Struct] + cases: Sequence[Tuple[EnumT, Struct]] + + def __post_init__(self): + object.__setattr__(self, "cases", tuple(self.cases)) @dataclass(frozen=True) @@ -114,6 +117,9 @@ class Struct: fields: Sequence[Field[Type]] + def __post_init__(self): + object.__setattr__(self, "fields", tuple(self.fields)) + @dataclass(frozen=True) class Command: @@ -125,6 +131,9 @@ class Command: reply: Optional[Struct] error: Set[ErrorType] + def __post_init__(self): + object.__setattr__(self, "error", frozenset(self.error)) + @dataclass(frozen=True) class CommandSet: @@ -133,3 +142,6 @@ class CommandSet: name: str id: int commands: Sequence[Command] + + def __post_init__(self): + object.__setattr__(self, "commands", tuple(self.commands)) diff --git a/projects/jdwp/tests/defs/schema.py b/projects/jdwp/tests/defs/schema.py index d845a45..2701a69 100644 --- a/projects/jdwp/tests/defs/schema.py +++ b/projects/jdwp/tests/defs/schema.py @@ -7,9 +7,13 @@ class SchemaTests(unittest.TestCase): def test_schema_can_be_imported(self): from projects.jdwp.defs.schema import OpaqueType - def test_command_sets_can_be_imported(self): + def test_command_sets_are_hashable(self): from projects.jdwp.defs.command_sets import ( event_request, reference_type, virtual_machine, ) + + hash(event_request.EventRequest) + hash(reference_type.ReferenceType) + hash(event_request.EventRequest)