Files
TransPyV/Test/App/namespace_defs.py
2026-07-19 13:18:46 +08:00

61 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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