Tsuchinokoトランスパイラが現在サポートしているPython機能の一覧です。
x: int = 10)int, float, str, bool, Nonelist[T], dict[K, V], tuple[...]Optional[T], T | Nonex or default → unwrap_or, 三項演算子+Noneチェック (V1.5.0)+, -, *, /, //, %, **, @ (V1.3.0)==, !=, <, >, <=, >=0 < x < 10 → 0 < x && x < 10) (V1.6.0)and, or, notin, not in (V1.3.0)is, is not (Noneとの比較)&, |, ^, ~, <<, >> (V1.3.0)+=, -=, *=, /=, //=, %=, **=, &=, |=, ^=, <<=, >>= (V1.3.0)range()、コレクション反復)x if cond else y)lambda x: x + 1)func(name="value"))def func(x=10)) (V1.2.0)def func(**kwargs) → HashMap<String, Value>) (V1.6.0){k: v for k, v in items}) (V1.3.0){1, 2, 3} → HashSet) (V1.5.0){x*2 for x in nums} → HashSet) (V1.6.0)nums[-1])[:3], [-3:], [1:n-1])[::2], [::-1]) (V1.5.0)a[i], a[j] = a[j], a[i] → a.swap())l.copy() → l.to_vec()) (V1.2.0)a, b, c = 1, 2, 3) (V1.3.0)pop, insert, remove, extend, clear (V1.5.0)keys, values, get, pop, update (V1.5.0)add, remove, discard, union, intersection (V1.5.0)__init__付きself.attr)@staticmethod)@dataclass) (V1.2.0 部分対応)class Child(Parent)) → コンポジション (V1.6.0)super().method() → self.base.method()) (V1.6.0)with open(...) as f: → { let f = ...; })Tsuchinoko V1.2.0 では、Rust への直接変換が困難なライブラリをサポートするために常駐 Python ワーカーを導入しました。
import numpy as np)import pandas as pd)import cv2) (V1.4.0)from インポート構文 (V1.4.0) 🆕from numpy import mean, stdpy_bridge.call_json("numpy.mean", ...) 呼び出しに自動変換Python オブジェクトをブリッジ呼び出しをまたいで保持できるようになりました:
df["column"])len() - 長さ取得range() - 数値範囲反復print() - コンソール出力 (f-string debug "{x=}" / "{:?}" 対応)list() - リスト変換min(), max() - 最小/最大値abs() - 絶対値int(), float(), str(), bool() - 型変換enumerate() - インデックス付きイテレーション (V1.3.0)zip() - 並列イテレーション (V1.3.0)sorted() - ソート済みリスト生成 (V1.3.0)reversed() - 逆順イテレーション (V1.3.0)sum() - 合計計算 (V1.3.0)all(), any() - 全要素/任意要素の真偽判定 (V1.3.0)map(), filter() - 関数型イテレータ変換 (V1.3.0)assert - アサーション文 (V1.3.0)input() - ユーザー入力(プロンプト付き) (V1.5.0)round() - 四捨五入(精度指定可) (V1.5.0)chr(), ord() - 文字・コードポイント変換 (V1.5.0)bin(), hex(), oct() - 数値フォーマット変換 (V1.5.0)isinstance() - 型チェック → DynamicValue enum + match (V1.6.0)math.sqrt, sin, cos, tan, asin, acos, atan, exp, log, log10, log2, abs, floor, ceil, roundmath.pi, math.e, math.tau, math.inf, math.nan → Rust ネイティブ定数に変換f"Hello {name}")
"{x=}" / "{:?}" 対応 (V1.2.0).upper(), .lower(), .strip(), .split(), .join() など.replace(), .startswith(), .endswith(), .find(), .rfind(), .index(), .count().isdigit(), .isalpha(), .isalnum()catch_unwindに変換)except (ValueError, TypeError):) (V1.5.0)except ValueError as e:) (V1.5.0)else 実行) (V1.5.2)Err(TsuchinokoError) または panic! に変換)raise A from B) - 例外チェーン (cause 保持) (V1.5.2)Result<T, TsuchinokoError> を返す (V1.5.2)TsuchinokoErrorに変換)MyType = list[int])Callable[[T], U])if x is None / if x is not None)[!NOTE] PyO3 の直接呼び出しも引き続きサポートされますが、互換性のために Resident Worker の使用を推奨します。