itf-py 0.1.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of itf-py might be problematic. Click here for more details.

itf_py/__init__.py CHANGED
@@ -7,4 +7,11 @@ from .itf import ITFState
7
7
  __version__ = "0.1.0"
8
8
  __all__ = [
9
9
  "ITFState",
10
+ "ITFTrace",
11
+ "value_to_json",
12
+ "value_from_json",
13
+ "state_to_json",
14
+ "state_from_json",
15
+ "trace_to_json",
16
+ "trace_from_json",
10
17
  ]
itf_py/itf.py CHANGED
@@ -1,7 +1,10 @@
1
+ from collections import namedtuple
1
2
  from dataclasses import dataclass
2
- from types import SimpleNamespace
3
3
  from typing import Any, Dict, List, Optional
4
4
 
5
+ from frozendict import frozendict
6
+ from frozenlist import FrozenList
7
+
5
8
 
6
9
  @dataclass
7
10
  class ITFState:
@@ -39,13 +42,17 @@ def value_from_json(val: Any) -> Any:
39
42
  elif "#set" in val:
40
43
  return frozenset(value_from_json(v) for v in val["#set"])
41
44
  elif "#map" in val:
42
- return {value_from_json(k): value_from_json(v) for (k, v) in val["#map"]}
45
+ d = {value_from_json(k): value_from_json(v) for (k, v) in val["#map"]}
46
+ return frozendict(d) # immutable dictionary
43
47
  elif "#unserializable" in val:
44
48
  return ITFUnserializable(value=val["#unserializable"])
45
49
  else:
46
- return SimpleNamespace(**{k: value_from_json(v) for k, v in val.items()})
50
+ tup_type = namedtuple("ITFRecord", val.keys()) # type: ignore
51
+ return tup_type(**{k: value_from_json(v) for k, v in val.items()})
47
52
  elif isinstance(val, list):
48
- return [value_from_json(v) for v in val]
53
+ lst = FrozenList([value_from_json(v) for v in val])
54
+ lst.freeze() # make it immutable
55
+ return lst
49
56
  else:
50
57
  return val # int, str, bool
51
58
 
@@ -56,16 +63,19 @@ def value_to_json(val: Any) -> Any:
56
63
  return val
57
64
  elif isinstance(val, int):
58
65
  return {"#bigint": str(val)}
59
- elif isinstance(val, tuple):
66
+ elif isinstance(val, tuple) and not hasattr(val, "_fields"):
60
67
  return {"#tup": [value_to_json(v) for v in val]}
61
68
  elif isinstance(val, frozenset):
62
69
  return {"#set": [value_to_json(v) for v in val]}
63
70
  elif isinstance(val, dict):
64
71
  return {"#map": [[value_to_json(k), value_to_json(v)] for k, v in val.items()]}
65
- elif isinstance(val, list):
72
+ elif isinstance(val, list) or isinstance(val, FrozenList):
66
73
  return [value_to_json(v) for v in val]
67
74
  elif hasattr(val, "__dict__"):
68
75
  return {k: value_to_json(v) for k, v in val.__dict__.items()}
76
+ elif isinstance(val, tuple) and hasattr(val, "_fields"):
77
+ # namedtuple
78
+ return {k: value_to_json(v) for k, v in val._asdict().items()} # type: ignore
69
79
  elif isinstance(val, str):
70
80
  return val
71
81
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: itf-py
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Python library to parse and emit Apalache ITF traces
5
5
  Keywords: itf,trace,parser,tlaplus,apalache,quint
6
6
  Author: Igor Konnov
@@ -9,6 +9,8 @@ Requires-Python: >=3.12,<4.0
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Programming Language :: Python :: 3.12
11
11
  Classifier: Programming Language :: Python :: 3.13
12
+ Requires-Dist: frozendict (>=2.4.6,<3.0.0)
13
+ Requires-Dist: frozenlist (>=1.7.0,<2.0.0)
12
14
  Project-URL: Homepage, https://github.com/konnov/itf-py
13
15
  Description-Content-Type: text/markdown
14
16
 
@@ -0,0 +1,5 @@
1
+ itf_py/__init__.py,sha256=zRXHiq7vDwHKepUc9RKs9oA57QBRKOZQRthHT3u0k5M,290
2
+ itf_py/itf.py,sha256=tiZR3g3-HRoDNk7eH26M7hxVyK3tMVGXhxsUxw-PCrQ,3934
3
+ itf_py-0.2.0.dist-info/METADATA,sha256=2E76gdEJiWOHZkmtwL_a_IiJSEPymqrxQWdNlx-8evo,1071
4
+ itf_py-0.2.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
5
+ itf_py-0.2.0.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- itf_py/__init__.py,sha256=TxSVie2ZFBXBjC11rLydd61ddyRgUjnCFo31CCk69aE,142
2
- itf_py/itf.py,sha256=OGTElw_qBsh0fngjw3PjGF-Q2dRXMwt6o-YT2xvZ2Pw,3438
3
- itf_py-0.1.1.dist-info/METADATA,sha256=ZUFtFuzvNuEZ-NRfvuRF48ZIY9rQxMj6fjiqYc8Ndjg,985
4
- itf_py-0.1.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
5
- itf_py-0.1.1.dist-info/RECORD,,
File without changes