修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
20
includes/ctraits.pyi
Normal file
20
includes/ctraits.pyi
Normal file
@@ -0,0 +1,20 @@
|
||||
"""ctraits — 编译时类型特征库
|
||||
|
||||
提供编译时类型判断函数,不纳入运行时编译。
|
||||
所有函数仅在编译时求值,可与 c.CIf 等编译时条件配合使用。
|
||||
"""
|
||||
import t
|
||||
|
||||
|
||||
def isptr(x: t.CType) -> bool:
|
||||
"""编译时判断 x 的类型是否为指针类型。
|
||||
|
||||
返回 True 如果 x 是指针(ptr_count > 0),否则返回 False。
|
||||
可与 c.CIf 配合使用实现条件编译。
|
||||
|
||||
示例:
|
||||
if c.CIf(ctraits.isptr(my_var)):
|
||||
# 仅当 my_var 是指针类型时编译此分支
|
||||
...
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user