This commit is contained in:
blueloveTH 2023-02-13 17:22:47 +08:00
parent 4e4ed4ddbd
commit d060c45928
4 changed files with 24 additions and 12 deletions

View File

@ -42,6 +42,7 @@ Please see https://pocketpy.dev for details or try [Live Demo](https://bluelovet
| Import | `import/from..import` | YES |
| Context Block | `with <expr> as <id>:` | YES |
| Type Annotation | `def f(a:int, b:float=1)` | YES |
| Generator | `yield i` | YES |
## Getting Started

View File

@ -38,6 +38,7 @@ PocketPy是一个轻量级的Python解释器为嵌入至游戏引擎而设计
| 导入模块 | `import/from..import` | YES |
| 上下文管理器 | `with <expr> as <id>:` | YES |
| 类型标注 | `def f(a:int, b:float=1)` | YES |
| 生成器 | `yield i` | YES |
## 快速上手

View File

@ -278,13 +278,19 @@ class dict:
return default
def keys(self):
return [kv[0] for kv in self._a if kv is not None]
for kv in self._a:
if kv is not None:
yield kv[0]
def values(self):
return [kv[1] for kv in self._a if kv is not None]
for kv in self._a:
if kv is not None:
yield kv[1]
def items(self):
return [kv for kv in self._a if kv is not None]
for kv in self._a:
if kv is not None:
yield kv
def clear(self):
self._a = [None] * self._capacity
@ -410,7 +416,7 @@ class set:
return '{'+ ', '.join(self._a.keys()) + '}'
def __iter__(self):
return self._a.keys().__iter__()
return self._a.keys()
)";
const char* kRandomCode = R"(

View File

@ -5,23 +5,25 @@ class A:
try:
a = A()
b = a[1]
exit(1)
except:
print("PASS 01")
pass
try:
a = {'1': 3, 4: None}
x = a[1]
exit(1)
except:
print("PASS 02")
pass
assert True
def f():
try:
raise KeyError('foo')
except A: # will fail to catch
assert False
exit(1)
except:
print("PASS 03")
pass
assert True
f()
@ -40,12 +42,14 @@ def f1():
try:
f1()
exit(1)
except KeyError:
print("PASS 04")
pass
assert True, "Msg"
try:
assert False, "Msg"
exit(1)
except AssertionError:
print("PASS 05")
pass