Skip to content

Commit a0de442

Browse files
committed
dev: Fix Revisions declaration in typed data module and RevisionField declaration in revisions module to prevent circular imports from occuring
1 parent de1f05a commit a0de442

File tree

5 files changed

+40
-37
lines changed

5 files changed

+40
-37
lines changed

starknet_py/hash/outside_execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from starknet_py.constants import OutsideExecutionInterfaceID
22
from starknet_py.net.client_models import OutsideExecution
3-
from starknet_py.net.schemas.common import Revision
3+
from starknet_py.net.models.typed_data import Revision
44
from starknet_py.utils.typed_data import TypedData
55

66
OUTSIDE_EXECUTION_INTERFACE_ID_TO_TYPED_DATA_REVISION = {

starknet_py/net/models/typed_data.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
"""
44

55
import sys
6+
from enum import Enum
67
from typing import Any, Dict, List, Optional, TypedDict
78

8-
from starknet_py.net.schemas.common import Revision
9-
109
if sys.version_info < (3, 11):
1110
from typing_extensions import NotRequired
1211
else:
1312
from typing import NotRequired
1413

1514

15+
class Revision(Enum):
16+
"""
17+
Enum representing the revision of the specification to be used.
18+
"""
19+
20+
V0 = 0
21+
V1 = 1
22+
23+
1624
class ParameterDict(TypedDict):
1725
"""
1826
TypedDict representing a Parameter object

starknet_py/net/schemas/common.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
import sys
3-
from enum import Enum
43
from typing import Any, Mapping, Optional, Union
54

65
from marshmallow import Schema, ValidationError, fields, post_load
@@ -377,35 +376,3 @@ class StorageEntrySchema(Schema):
377376
def make_dataclass(self, data, **kwargs):
378377
# pylint: disable=no-self-use
379378
return StorageEntry(**data)
380-
381-
382-
class Revision(Enum):
383-
"""
384-
Enum representing the revision of the specification to be used.
385-
"""
386-
387-
V0 = 0
388-
V1 = 1
389-
390-
391-
class RevisionField(fields.Field):
392-
def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs):
393-
if value is None or value == Revision.V0:
394-
return str(Revision.V0.value)
395-
return value.value
396-
397-
def _deserialize(self, value, attr, data, **kwargs) -> Revision:
398-
if isinstance(value, str):
399-
value = int(value)
400-
401-
if isinstance(value, Revision):
402-
value = value.value
403-
404-
revisions = [revision.value for revision in Revision]
405-
if value not in revisions:
406-
allowed_revisions_str = "".join(list(map(str, revisions)))
407-
raise ValidationError(
408-
f"Invalid value provided for Revision: {value}. Allowed values are {allowed_revisions_str}."
409-
)
410-
411-
return Revision(value)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Any, Optional
2+
3+
from marshmallow import ValidationError, fields
4+
5+
from starknet_py.net.models.typed_data import Revision
6+
7+
8+
class RevisionField(fields.Field):
9+
def _serialize(self, value: Any, attr: Optional[str], obj: Any, **kwargs):
10+
if value is None or value == Revision.V0:
11+
return str(Revision.V0.value)
12+
return value.value
13+
14+
def _deserialize(self, value, attr, data, **kwargs) -> Revision:
15+
if isinstance(value, str):
16+
value = int(value)
17+
18+
if isinstance(value, Revision):
19+
value = value.value
20+
21+
revisions = [revision.value for revision in Revision]
22+
if value not in revisions:
23+
allowed_revisions_str = "".join(list(map(str, revisions)))
24+
raise ValidationError(
25+
f"Invalid value provided for Revision: {value}. Allowed values are {allowed_revisions_str}."
26+
)
27+
28+
return Revision(value)

starknet_py/utils/typed_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from starknet_py.hash.selector import get_selector_from_name
1313
from starknet_py.net.client_utils import _to_rpc_felt
1414
from starknet_py.net.models.typed_data import DomainDict, Revision, TypedDataDict
15-
from starknet_py.net.schemas.common import RevisionField
15+
from starknet_py.net.schemas.revision import RevisionField
1616
from starknet_py.serialization.data_serializers import ByteArraySerializer
1717
from starknet_py.utils.merkle_tree import MerkleTree
1818

0 commit comments

Comments
 (0)