snapshot before regression test
This commit is contained in:
60
TransPyV/Test/App/namespace_defs.py
Normal file
60
TransPyV/Test/App/namespace_defs.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import stdio
|
||||
import t, c
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 命名空间隔离测试:定义类模块
|
||||
#
|
||||
# 本文件定义供其他文件 import 使用的类,验证跨模块命名空间隔离:
|
||||
# - 裸名 Class(): 需要 from namespace_defs import Class
|
||||
# - 模块限定 namespace_defs.Class(): 需要 import namespace_defs
|
||||
# ============================================================
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 带虚表的类 Widget
|
||||
# ============================================================
|
||||
@t.CVTable
|
||||
class Widget:
|
||||
id: t.CInt
|
||||
|
||||
def __init__(self, i: t.CInt):
|
||||
self.id = i
|
||||
|
||||
def GetId(self) -> t.CInt:
|
||||
return self.id
|
||||
|
||||
def Render(self) -> t.CInt:
|
||||
return 100
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 子类 Gadget(继承 Widget,覆盖 Render)
|
||||
# ============================================================
|
||||
class Gadget(Widget):
|
||||
extra: t.CInt
|
||||
|
||||
def __init__(self, i: t.CInt, e: t.CInt):
|
||||
self.id = i
|
||||
self.extra = e
|
||||
|
||||
def Render(self) -> t.CInt:
|
||||
return 200
|
||||
|
||||
def GetExtra(self) -> t.CInt:
|
||||
return self.extra
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 普通结构体 PlainStruct(无虚表)
|
||||
# ============================================================
|
||||
class PlainStruct:
|
||||
x: t.CInt
|
||||
y: t.CInt
|
||||
|
||||
def __init__(self, ax: t.CInt, ay: t.CInt):
|
||||
self.x = ax
|
||||
self.y = ay
|
||||
|
||||
def Sum(self) -> t.CInt:
|
||||
return self.x + self.y
|
||||
Reference in New Issue
Block a user