cbridge 0.2.0__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cbridge
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Creating ctype structure like dataclass
5
5
  Author: ZhengYu, Xu
6
6
  Author-email: ZhengYu, Xu <zen-xu@outlook.com>
@@ -177,9 +177,6 @@ print(Config(name=b"test")) # Config(name=b'test', timeout=30, flags=[0, 1])
177
177
 
178
178
  ### Pointer Operations
179
179
 
180
- > [!WARNING]
181
- > Python 3.13 and above are currently not supported forward declarations
182
-
183
180
  ```python
184
181
  from cbridge import CStruct
185
182
  from cbridge import types
@@ -154,9 +154,6 @@ print(Config(name=b"test")) # Config(name=b'test', timeout=30, flags=[0, 1])
154
154
 
155
155
  ### Pointer Operations
156
156
 
157
- > [!WARNING]
158
- > Python 3.13 and above are currently not supported forward declarations
159
-
160
157
  ```python
161
158
  from cbridge import CStruct
162
159
  from cbridge import types
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cbridge"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  authors = [{ name = "ZhengYu, Xu", email = "zen-xu@outlook.com" }]
5
5
  description = "Creating ctype structure like dataclass"
6
6
  requires-python = ">=3.9"
@@ -5,7 +5,7 @@ from .cbridge import field
5
5
  from .cfunc import cfunc
6
6
 
7
7
 
8
- __version__ = "0.2.0"
8
+ __version__ = "0.2.2"
9
9
  __authors__ = [
10
10
  "ZhengYu, Xu <zen-xu@outlook.com>",
11
11
  ]
@@ -36,10 +36,24 @@ class CStructType(_CStructType):
36
36
  pack: int = 0,
37
37
  **extra,
38
38
  ):
39
- if sys.version_info >= (3, 13):
40
- attrs["_fields_"] = []
41
- attrs["_pack_"] = pack
42
- cls = super().__new__(meta_self, name, bases, attrs)
39
+ if pack:
40
+ attrs["_pack_"] = pack
41
+ # Python 3.14+ only allows _pack_ with the MSVC-compatible layout
42
+ attrs["_layout_"] = "ms"
43
+ return super().__new__(meta_self, name, bases, attrs)
44
+
45
+ # Since Python 3.13, ctypes initializes structure storage info in tp_init
46
+ # instead of tp_new, so field resolution (which may create pointers to the
47
+ # class itself for forward declarations) must happen after super().__init__
48
+ def __init__(
49
+ cls, # noqa: N805
50
+ name: str,
51
+ bases: tuple[type, ...],
52
+ attrs: dict[str, Any],
53
+ pack: int = 0,
54
+ **extra,
55
+ ):
56
+ super().__init__(name, bases, attrs)
43
57
  fields_map = {
44
58
  f_name: f_type
45
59
  for f_name, f_type in get_type_hints(
@@ -50,14 +64,11 @@ class CStructType(_CStructType):
50
64
  fields = list(fields_map.items())
51
65
  if fields:
52
66
  # update fields
53
- if sys.version_info >= (3, 13):
54
- cls._fields_[:] = fields
55
- else:
56
- cls._fields_ = fields
67
+ cls._fields_ = fields
57
68
 
58
- cls = ds.dataclass(cls)
69
+ ds.dataclass(cls)
59
70
 
60
- @wraps(cls.__init__)
71
+ @wraps(cls.__init__) # type: ignore[misc]
61
72
  def wrapped_init(self, *args, **kwargs):
62
73
  args = list(args)
63
74
 
@@ -86,9 +97,7 @@ class CStructType(_CStructType):
86
97
 
87
98
  return ctypes.Structure.__init__(self, **kwargs)
88
99
 
89
- cls.__init__ = wrapped_init
90
-
91
- return cls
100
+ cls.__init__ = wrapped_init # type: ignore[misc]
92
101
 
93
102
 
94
103
  field = ds.field
@@ -1,4 +1,5 @@
1
1
  # pyright: reportGeneralTypeIssues=false
2
+ import builtins
2
3
  import ctypes
3
4
 
4
5
  from collections.abc import Sequence
@@ -18,6 +19,10 @@ if TYPE_CHECKING:
18
19
  from typing_extensions import Self
19
20
 
20
21
  class CData(_CData, Generic[_T]):
22
+ def __lt__(self, other: Any) -> bool: ...
23
+ def __le__(self, other: Any) -> bool: ...
24
+ def __gt__(self, other: Any) -> bool: ...
25
+ def __ge__(self, other: Any) -> bool: ...
21
26
  def __iadd__(self, other: _T) -> Self: ...
22
27
  def __isub__(self, other: _T) -> Self: ...
23
28
  def __imul__(self, other: _T) -> Self: ...
@@ -47,32 +52,33 @@ if TYPE_CHECKING:
47
52
  def __abs__(self) -> Self: ...
48
53
  def __invert__(self) -> Self: ...
49
54
 
50
- bool = Union[bool, CData[bool]]
51
- byte = Union[bytes, CData[bytes]]
52
- char = Union[bytes, CData[bytes]]
53
- double = Union[float, CData[float]]
54
- float = Union[float, CData[float]]
55
- ubyte = Union[bytes, CData[bytes]]
56
- int = Union[int, CData[int]]
57
- int8 = Union[int, CData[int]]
58
- int16 = Union[int, CData[int]]
59
- int32 = Union[int, CData[int]]
60
- int64 = Union[int, CData[int]]
61
- long = Union[int, CData[int]]
62
- longdouble = Union[float, CData[float]]
63
- longlong = Union[float, CData[float]]
64
- short = Union[int, CData[int]]
65
- size_t = Union[int, CData[int]]
66
- ssize_t = Union[int, CData[int]]
67
- uint = Union[int, CData[int]]
68
- uint8 = Union[int, CData[int]]
69
- uint16 = Union[int, CData[int]]
70
- uint32 = Union[int, CData[int]]
71
- uint64 = Union[int, CData[int]]
72
- ulong = Union[int, CData[int]]
73
- ulonglong = Union[int, CData[int]]
74
- ushort = Union[int, CData[int]]
75
- wchar = Union[str, CData[str]]
55
+ _CDataType = Union[_T, CData[_T]]
56
+ bool = _CDataType[builtins.bool]
57
+ byte = _CDataType[builtins.bytes]
58
+ char = _CDataType[builtins.bytes]
59
+ double = _CDataType[builtins.float]
60
+ float = _CDataType[builtins.float]
61
+ ubyte = _CDataType[builtins.bytes]
62
+ int = _CDataType[builtins.int]
63
+ int8 = _CDataType[builtins.int]
64
+ int16 = _CDataType[builtins.int]
65
+ int32 = _CDataType[builtins.int]
66
+ int64 = _CDataType[builtins.int]
67
+ long = _CDataType[builtins.int]
68
+ longdouble = _CDataType[builtins.float]
69
+ longlong = _CDataType[builtins.float]
70
+ short = _CDataType[builtins.int]
71
+ size_t = _CDataType[builtins.int]
72
+ ssize_t = _CDataType[builtins.int]
73
+ uint = _CDataType[builtins.int]
74
+ uint8 = _CDataType[builtins.int]
75
+ uint16 = _CDataType[builtins.int]
76
+ uint32 = _CDataType[builtins.int]
77
+ uint64 = _CDataType[builtins.int]
78
+ ulong = _CDataType[builtins.int]
79
+ ulonglong = _CDataType[builtins.int]
80
+ ushort = _CDataType[builtins.int]
81
+ wchar = _CDataType[builtins.str]
76
82
  void_ptr = Union[ctypes.c_void_p, Any]
77
83
 
78
84
  _Len = TypeVar("_Len")
@@ -126,8 +132,6 @@ else:
126
132
  char_ptr = ctypes.c_char_p
127
133
  wchar_ptr = ctypes.c_wchar_p
128
134
 
129
- import builtins
130
-
131
135
  from typing import get_args
132
136
 
133
137
  class Array:
File without changes
File without changes