construct-classes 0.2.1__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,25 @@ 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.1...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
+
24
+
25
+ 0.2.2 - 2025-08-26
26
+ --------------------
27
+
28
+ Removed
29
+ ~~~~~~~
30
+
31
+ - Drop support for Pythons 3.9 and older. This was broken in 0.2 and improperly marked
32
+ by the package metadata.
15
33
 
16
34
  0.2.1 - 2025-08-25
17
35
  --------------------
@@ -45,7 +63,7 @@ Incompatible changes
45
63
  Fixed
46
64
  ~~~~~
47
65
 
48
- - Support for dataclasses that do not contain all the attributes described
66
+ - Support for dataclasses that do not contain all the attributes described
49
67
  in :code:`SUBCON`.
50
68
 
51
69
 
@@ -1,30 +1,24 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: construct-classes
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Parse your binary structs into dataclasses
5
- Home-page: https://github.com/matejcik/construct-classes
6
- License: MIT
7
- Author: matejcik
8
- Author-email: ja@matejcik.cz
9
- Requires-Python: >=3.6.2,<4.0
5
+ Author-email: matejcik <ja@matejcik.cz>
6
+ Requires-Python: >=3.10,<4.0
7
+ Description-Content-Type: text/x-rst
8
+ License-Expression: MIT
10
9
  Classifier: Development Status :: 2 - Pre-Alpha
11
10
  Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
11
  Classifier: Natural Language :: English
14
12
  Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.7
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: 3.9
18
13
  Classifier: Programming Language :: Python :: 3.10
19
14
  Classifier: Programming Language :: Python :: 3.11
20
15
  Classifier: Programming Language :: Python :: 3.12
21
16
  Classifier: Programming Language :: Python :: 3.13
22
17
  Classifier: Programming Language :: Python :: 3.14
23
- Classifier: Programming Language :: Python :: 3.6
24
- Requires-Dist: construct (>=2.10,<3.0)
25
- Requires-Dist: dataclasses (>=0.8,<0.9) ; python_full_version >= "3.6.0" and python_full_version < "3.7.0"
18
+ License-File: LICENSE
19
+ Requires-Dist: construct~=2.10
20
+ Project-URL: Homepage, https://github.com/matejcik/construct-classes
26
21
  Project-URL: Repository, https://github.com/matejcik/construct-classes
27
- Description-Content-Type: text/x-rst
28
22
 
29
23
  =================
30
24
  construct-classes
@@ -0,0 +1,51 @@
1
+ [project]
2
+ name = "construct-classes"
3
+ version = "0.2.3"
4
+ description = "Parse your binary structs into dataclasses"
5
+ authors = [{ name = "matejcik", email = "ja@matejcik.cz" }]
6
+ requires-python = ">=3.10,<4.0"
7
+ readme = "README.rst"
8
+ license = "MIT"
9
+ classifiers = [
10
+ "Development Status :: 2 - Pre-Alpha",
11
+ "Intended Audience :: Developers",
12
+ "Natural Language :: English",
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ ]
20
+ dependencies = [
21
+ "construct~=2.10",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/matejcik/construct-classes"
26
+ Repository = "https://github.com/matejcik/construct-classes"
27
+
28
+ [dependency-groups]
29
+ dev = [
30
+ "pytest>5",
31
+ "black>=22.8.0,<23",
32
+ "isort>=5.10.1,<6",
33
+ "flake8>=5.0.4,<6",
34
+ "construct-typing>=0.5.2,<0.6",
35
+ "typing-extensions>4.2",
36
+ ]
37
+
38
+ [build-system]
39
+ requires = ["flit_core>=3.4,<4"]
40
+ build-backend = "flit_core.buildapi"
41
+
42
+ [tool.flit.sdist]
43
+ include = [
44
+ "CHANGELOG.rst",
45
+ "LICENSE",
46
+ "README.rst",
47
+ "tests/",
48
+ ]
49
+
50
+ [tool.isort]
51
+ profile = "black"
@@ -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
@@ -1,50 +0,0 @@
1
- [tool.poetry]
2
- name = "construct-classes"
3
- version = "0.2.1"
4
- authors = ["matejcik <ja@matejcik.cz>"]
5
- classifiers = [
6
- "Development Status :: 2 - Pre-Alpha",
7
- "Intended Audience :: Developers",
8
- "License :: OSI Approved :: MIT License",
9
- "Natural Language :: English",
10
- "Programming Language :: Python :: 3",
11
- "Programming Language :: Python :: 3.6",
12
- "Programming Language :: Python :: 3.7",
13
- "Programming Language :: Python :: 3.8",
14
- "Programming Language :: Python :: 3.9",
15
- "Programming Language :: Python :: 3.10",
16
- "Programming Language :: Python :: 3.11",
17
- "Programming Language :: Python :: 3.12",
18
- "Programming Language :: Python :: 3.13",
19
- "Programming Language :: Python :: 3.14",
20
- ]
21
- description = "Parse your binary structs into dataclasses"
22
- homepage = "https://github.com/matejcik/construct-classes"
23
- license = "MIT"
24
- repository = "https://github.com/matejcik/construct-classes"
25
- readme = "README.rst"
26
- include = [
27
- { path = "CHANGELOG.rst", format = "sdist" },
28
- { path = "LICENSE", format = "sdist" },
29
- { path = "README.rst", format = "sdist" }
30
- ]
31
-
32
- [tool.poetry.dependencies]
33
- python = ">=3.6.2,<4.0"
34
- construct = "^2.10"
35
- dataclasses = { version = "^0.8", python = "~3.6.0" }
36
-
37
- [tool.poetry.dev-dependencies]
38
- pytest = ">5"
39
- black = "^22.8.0"
40
- isort = "^5.10.1"
41
- flake8 = "^5.0.4"
42
- construct-typing = { version = "^0.5.2", python = ">=3.7" }
43
- typing-extensions = { version = ">4.2", python = ">=3.7" }
44
-
45
- [build-system]
46
- requires = ["poetry-core>=1.0.0"]
47
- build-backend = "poetry.core.masonry.api"
48
-
49
- [tool.isort]
50
- profile = "black"