construct-classes 0.2.2__tar.gz → 0.2.3__tar.gz

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.
@@ -11,7 +11,16 @@ Unreleased
11
11
 
12
12
  Please see all `Unreleased Changes`_ for more information.
13
13
 
14
- .. _Unreleased Changes: https://github.com/matejcik/construct-classes/compare/v0.2.2...HEAD
14
+ .. _Unreleased Changes: https://github.com/matejcik/construct-classes/compare/v0.2.3...HEAD
15
+
16
+ 0.2.3 - 2026-03-31
17
+ ------------------
18
+
19
+ Changed
20
+ ~~~~~~~
21
+
22
+ - Use :code:`flit_core` for building the package.
23
+
15
24
 
16
25
  0.2.2 - 2025-08-26
17
26
  --------------------
@@ -54,7 +63,7 @@ Incompatible changes
54
63
  Fixed
55
64
  ~~~~~
56
65
 
57
- - Support for dataclasses that do not contain all the attributes described
66
+ - Support for dataclasses that do not contain all the attributes described
58
67
  in :code:`SUBCON`.
59
68
 
60
69
 
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: construct-classes
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Parse your binary structs into dataclasses
5
- Author: matejcik
6
5
  Author-email: matejcik <ja@matejcik.cz>
6
+ Requires-Python: >=3.10,<4.0
7
+ Description-Content-Type: text/x-rst
7
8
  License-Expression: MIT
8
9
  Classifier: Development Status :: 2 - Pre-Alpha
9
10
  Classifier: Intended Audience :: Developers
10
- Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Natural Language :: English
12
12
  Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.10
@@ -15,11 +15,10 @@ Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: 3.14
18
+ License-File: LICENSE
18
19
  Requires-Dist: construct~=2.10
19
- Requires-Python: >=3.10, <4.0
20
20
  Project-URL: Homepage, https://github.com/matejcik/construct-classes
21
21
  Project-URL: Repository, https://github.com/matejcik/construct-classes
22
- Description-Content-Type: text/x-rst
23
22
 
24
23
  =================
25
24
  construct-classes
@@ -145,3 +144,4 @@ Footer
145
144
  * Free software: MIT License
146
145
 
147
146
  .. * Documentation: https://construct-classes.readthedocs.io.
147
+
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "construct-classes"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Parse your binary structs into dataclasses"
5
5
  authors = [{ name = "matejcik", email = "ja@matejcik.cz" }]
6
6
  requires-python = ">=3.10,<4.0"
@@ -9,7 +9,6 @@ license = "MIT"
9
9
  classifiers = [
10
10
  "Development Status :: 2 - Pre-Alpha",
11
11
  "Intended Audience :: Developers",
12
- "License :: OSI Approved :: MIT License",
13
12
  "Natural Language :: English",
14
13
  "Programming Language :: Python :: 3",
15
14
  "Programming Language :: Python :: 3.10",
@@ -37,14 +36,15 @@ dev = [
37
36
  ]
38
37
 
39
38
  [build-system]
40
- requires = ["uv_build>=0.8.13,<0.9.0"]
41
- build-backend = "uv_build"
39
+ requires = ["flit_core>=3.4,<4"]
40
+ build-backend = "flit_core.buildapi"
42
41
 
43
- [tool.uv.build-backend]
44
- source-include = [
42
+ [tool.flit.sdist]
43
+ include = [
45
44
  "CHANGELOG.rst",
46
45
  "LICENSE",
47
46
  "README.rst",
47
+ "tests/",
48
48
  ]
49
49
 
50
50
  [tool.isort]
@@ -0,0 +1,118 @@
1
+ import typing as t
2
+ from dataclasses import FrozenInstanceError
3
+
4
+ import construct as c
5
+ import pytest
6
+
7
+ from construct_classes import Struct, subcon
8
+
9
+
10
+ class BasicStruct(Struct):
11
+ a: int
12
+ b: int
13
+
14
+ SUBCON = c.Struct(
15
+ "a" / c.Int8ub,
16
+ "b" / c.Int8ub,
17
+ )
18
+
19
+
20
+ def test_basic():
21
+ bs = BasicStruct(a=5, b=10)
22
+
23
+ compiled = bs.build()
24
+ parsed = BasicStruct.parse(compiled)
25
+ assert parsed == bs
26
+
27
+
28
+ class SubconStruct(Struct):
29
+ a: int
30
+ b: BasicStruct = subcon(BasicStruct)
31
+
32
+ SUBCON = c.Struct(
33
+ "a" / c.Int8ub,
34
+ "b" / BasicStruct.SUBCON,
35
+ )
36
+
37
+
38
+ def test_subcon():
39
+ ss = SubconStruct(a=5, b=BasicStruct(a=10, b=20))
40
+
41
+ compiled = ss.build()
42
+ parsed = SubconStruct.parse(compiled)
43
+ assert parsed == ss
44
+
45
+ substr = parsed.b.build()
46
+ assert substr in compiled
47
+
48
+
49
+ class WithDefaultFactory(Struct):
50
+ array: t.List[BasicStruct] = subcon(BasicStruct, default_factory=list)
51
+
52
+ SUBCON = c.Struct(
53
+ "array" / c.Array(2, BasicStruct.SUBCON),
54
+ )
55
+
56
+
57
+ def test_default():
58
+ dd = WithDefaultFactory()
59
+ assert dd.array == []
60
+
61
+
62
+ class MoreFieldsInConstruct(Struct):
63
+ a: int
64
+
65
+ SUBCON = c.Struct(
66
+ "a" / c.Int8ub,
67
+ "b" / c.Tell,
68
+ )
69
+
70
+
71
+ def test_more_fields():
72
+ MoreFieldsInConstruct.parse(b"\x01")
73
+
74
+
75
+ class DefaultsNotLast(Struct):
76
+ a: int = 1
77
+ b: int
78
+
79
+ SUBCON = c.Struct(
80
+ "a" / c.Int8ub,
81
+ "b" / c.Int8ub,
82
+ )
83
+
84
+
85
+ def test_defaults_not_last():
86
+ rebuilt = DefaultsNotLast(b=5).build()
87
+ reparsed = DefaultsNotLast.parse(rebuilt)
88
+ assert reparsed.a == 1
89
+ assert reparsed.b == 5
90
+
91
+
92
+ class DataclassPassthrough(Struct, frozen=True, eq=False):
93
+ a: int
94
+
95
+ SUBCON = c.Struct(
96
+ "a" / c.Int8ub,
97
+ )
98
+
99
+
100
+ def test_dataclass_passthrough():
101
+ a = DataclassPassthrough(a=1)
102
+ with pytest.raises(FrozenInstanceError):
103
+ a.a = 2 # type: ignore # yes, it is an error
104
+ assert a.a == 1
105
+
106
+ # eq is not implemented
107
+ b = DataclassPassthrough(a=1)
108
+ assert a != b
109
+
110
+
111
+ def test_indirect_descendant():
112
+ """
113
+ regression test for #5: a subclass of a subclass of a Struct would have caused an
114
+ exception on definition
115
+ """
116
+
117
+ class Sub(BasicStruct):
118
+ pass