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 | | Import | `import/from..import` | YES |
| Context Block | `with <expr> as <id>:` | YES | | Context Block | `with <expr> as <id>:` | YES |
| Type Annotation | `def f(a:int, b:float=1)` | YES | | Type Annotation | `def f(a:int, b:float=1)` | YES |
| Generator | `yield i` | YES |
## Getting Started ## Getting Started

View File

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

View File

@ -278,13 +278,19 @@ class dict:
return default return default
def keys(self): 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): 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): 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): def clear(self):
self._a = [None] * self._capacity self._a = [None] * self._capacity
@ -410,7 +416,7 @@ class set:
return '{'+ ', '.join(self._a.keys()) + '}' return '{'+ ', '.join(self._a.keys()) + '}'
def __iter__(self): def __iter__(self):
return self._a.keys().__iter__() return self._a.keys()
)"; )";
const char* kRandomCode = R"( const char* kRandomCode = R"(

View File

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