CurlyPython
用大括号风格写 Python 的奇妙小工具
这是什么?
一个让 Python 支持大括号语法的转换工具:
这样写 Python
def main() {
for i in range(5) {
if (i % 2 == 0) {
print(f"{i} is even");
} else {
print(f"{i} is odd");
}
}
}
class Calculator {
def __init__(self, value = 0) {
self._value = value;
}
def add(self, x) {
self._value += x;
return self;
}
staticmethod def helper() {
return "I'm a static method";
}
property def value(self) {
return self._value;
}
}
甚至这样
def main() {for i in range(5) {if (i % 2 == 0) {print(f"{i} is even");} else {print(f"{i} is odd");}}}class Calculator {def __init__(self, value = 0) {self.value = value or 0}def add(self, x) {self.value += x;return self;}staticmethod def helper() {return "I'm a static method";}}
特色功能
- ✅ 大括号自动转缩进
- ✅ 静态方法支持
- ✅ 装饰器支持
- ✅ 增量赋值支持
- 🚧 更多语法糖陆续添加...
注意
这只是一个趣味项目:
- 不是真正的编译器
- 不追求完整语法兼容
- 核心是让 Python 支持大括号写法
适合:
- 喜欢大括号的程序员
- 想换个风格写 Python
安装使用
# 运行文件
curpy my_script.curpy
# 解析为 python
curpy my_script.curpy -o my_script.py
语法对照
| CurlyPython | Python |
|---|---|
def foo() { ... } |
def foo(): ... |
if (x) { ... } |
if x: ... |
class Bar { ... } |
class Bar: ... |
decorator class/def |
@decorator + class/def |
i++ / i-- |
i += 1 / i -= 1 |
else if / elif |
elif |
- 注意 : 所有
def和class前的内容都会被解析为装饰器,支持多重装饰器 - 注意 : 语法不支持列表推导式及字典推导式
扩展功能
如果在使用时加上-E参数,则开启扩展功能
curpy my_script.curpy -E
扩展功能语法
| CurlyPython | Python |
|---|---|
static def |
@staticmethod |
virtual def |
@abstractmethod |
struct class |
@dataclass |
MyClass::method() |
MyClass.method() |
- 注意 : 解析器会自动处理导入
示例
class MyClass() {
virtual static def hello() {
print("Hello, world!");
}
}
转换后
from abc import abstractmethod
class MyClass() :
@abstractmethod
@staticmethod
def hello() :
print("Hello, world!")
Metadata
Release files for curlypython 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| curlypython-0.1.0.tar.gz | 18.8 kB | Without provenance | Details for curlypython-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| curlypython-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for curlypython-0.1.0-py3-none-any.whl |
Total release size: 38.9 kB
Release files / curlypython-0.1.0.tar.gz
| Download URL | curlypython-0.1.0.tar.gz |
|---|---|
| Size | 18.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a2eb647c0d444a7e7c49899094483c581f8ad6a7f6d038704dcce2945b54345
|
|
BLAKE2b-256 checksum How to use checksums |
81479069d3ea8cbb7a3f1aeb73d2ebac35ee44090b8b4ed22be5d3d151aedb4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / curlypython-0.1.0-py3-none-any.whl
| Download URL | curlypython-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8e4d36a52ff5bd439730c6ea4eacebcd342e11d443937e9c1a964baee5ae4268
|
|
BLAKE2b-256 checksum How to use checksums |
7a0aa277e3fa1cb66ff839a469421ddeebc8bf6fc89122e4ee29a5d9e272f81f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for curlypython 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.