test: 泛型类注解补全类型实参(G5 的 GSList[G5Node]、VectorGenericTest 的 Vector[CInt]/[CFloat64T])

配合 TransPyV 新增的「泛型类注解必须带类型实参」fail-fast,把裸泛型注解改为带实参写法。
This commit is contained in:
TermiNexus committed 2026-10-03 11:16:47 +08:00
1 parent f15bb0bc8e
commit 76e1acf4da
2 files changed
+12 -12

No files matched your search

+10 -10
View File
@@ -53,7 +53,7 @@ def new_g5node(pool: memhub.MemBuddy | t.CPtr) -> G5Node | t.CPtr:
# GSList 硬编码大小: Head(8) + Tail(8) + Count(8) = 24 字节
G5LIST_SIZE: t.CDefine = 24
def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList | t.CPtr:
def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList[G5Node] | t.CPtr:
"""从 pool 分配并零初始化一个 GSList 容器(Head/Tail/Count 全零)"""
gsl: t.CPtr = pool.alloc(G5LIST_SIZE)
if gsl is None: return None
@@ -83,43 +83,43 @@ def new_g5container(pool: memhub.MemBuddy | t.CPtr) -> G5Container | t.CPtr:
# 所有字段。其他模块通过函数调用获取字段值,绕过 stub 限制。
# ============================================================
def g5list_get_head(lst: GSList | t.CPtr) -> G5Node | t.CPtr:
def g5list_get_head(lst: GSList[G5Node] | t.CPtr) -> G5Node | t.CPtr:
"""获取链表头节点"""
if lst is None: return None
return lst.Head
def g5list_get_tail(lst: GSList | t.CPtr) -> G5Node | t.CPtr:
def g5list_get_tail(lst: GSList[G5Node] | t.CPtr) -> G5Node | t.CPtr:
"""获取链表尾节点"""
if lst is None: return None
return lst.Tail
def g5list_get_count(lst: GSList | t.CPtr) -> t.CSizeT:
def g5list_get_count(lst: GSList[G5Node] | t.CPtr) -> t.CSizeT:
"""获取链表节点数"""
if lst is None: return 0
return lst.Count
def g5list_set_head(lst: GSList | t.CPtr, node: G5Node | t.CPtr):
def g5list_set_head(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr):
"""设置链表头节点"""
if lst is None: return
lst.Head = node
def g5list_set_tail(lst: GSList | t.CPtr, node: G5Node | t.CPtr):
def g5list_set_tail(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr):
"""设置链表尾节点"""
if lst is None: return
lst.Tail = node
def g5list_set_count(lst: GSList | t.CPtr, count: t.CSizeT):
def g5list_set_count(lst: GSList[G5Node] | t.CPtr, count: t.CSizeT):
"""设置链表节点数"""
if lst is None: return
lst.Count = count
def g5list_append(lst: GSList | t.CPtr, node: G5Node | t.CPtr):
def g5list_append(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr):
"""将 node 追加到链表末尾(O(1))
直接操作 Head/Tail/Count 字段,不依赖 GSList.append 方法
@@ -163,11 +163,11 @@ def g5node_set_next(node: G5Node | t.CPtr, next_node: G5Node | t.CPtr):
# G5Container 访问器
# ============================================================
def g5container_get_list(container: G5Container | t.CPtr) -> GSList | t.CPtr:
def g5container_get_list(container: G5Container | t.CPtr) -> GSList[G5Node] | t.CPtr:
if container is None: return None
return container.List
def g5container_set_list(container: G5Container | t.CPtr, lst: GSList | t.CPtr):
def g5container_set_list(container: G5Container | t.CPtr, lst: GSList[G5Node] | t.CPtr):
if container is None: return
container.List = lst
+2 -2
View File
@@ -12,7 +12,7 @@ def vector_main() -> CInt:
pool_mem: t.CPtr = stdlib.malloc(POOL_SIZE)
pool: memhub.MemPool | CPtr = memhub.MemPool(pool_mem, POOL_SIZE)
vi: vector.Vector | CPtr = vector.Vector(pool, 10, CInt(0))
vi: vector.Vector[CInt] | CPtr = vector.Vector(pool, 10, CInt(0))
vi.push(CInt(10))
vi.push(CInt(20))
vi.push(CInt(30))
@@ -29,7 +29,7 @@ def vector_main() -> CInt:
vi.free()
vd: vector.Vector | CPtr = vector.Vector(pool, 8, CFloat64T(0.0))
vd: vector.Vector[CFloat64T] | CPtr = vector.Vector(pool, 8, CFloat64T(0.0))
vd.push(CFloat64T(1.5))
vd.push(CFloat64T(2.7))
vd.push(CFloat64T(3.14))