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 |
|
| 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
|
||||||
|
|
||||||
|
@ -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 |
|
||||||
|
|
||||||
## 快速上手
|
## 快速上手
|
||||||
|
|
||||||
|
@ -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"(
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user