mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
up
This commit is contained in:
parent
4e4ed4ddbd
commit
d060c45928
@ -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
|
||||
|
||||
|
@ -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 |
|
||||
|
||||
## 快速上手
|
||||
|
||||
|
@ -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"(
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user