Skip to content

Experience-Driven Black-Box Cost Control for Coding Agents

fix(microskills): pass re.split maxsplit by keyword

Imtias Sabbirab5488f947e5
diff --git a/tests/test_observe_label_failed.py b/tests/test_observe_label_failed.py
new file mode 100644
index 0000000..19218d5
--- /dev/null
+++ b/tests/test_observe_label_failed.py
@@ -0,0 +1,11 @@
+import warnings
+
+from tokeneconomizer.microskills.observe import _label_failed
+
+
+def test_label_failed_matches_the_labels_own_module_without_deprecation_warnings():
+ # Python 3.13 deprecates passing re.split's maxsplit positionally.
+ with warnings.catch_warnings():
+ warnings.simplefilter("error", DeprecationWarning)
+ assert _label_failed(["tests.app:Case"], "No module named 'tests'")
+ assert not _label_failed(["tests/app.py"], "No module named 'pytest'")
diff --git a/tokeneconomizer/microskills/observe.py b/tokeneconomizer/microskills/observe.py
index ceddc5c..5fdd44d 100644
--- a/tokeneconomizer/microskills/observe.py
+++ b/tokeneconomizer/microskills/observe.py
@@ -488,7 +488,7 @@ def _label_failed(labels, out):
cannot import is the label's own (`tests` for `tests.app`) -- a missing `pytest` is not."""
if _LABEL_ERR_RE.search(out or ""):
return True
- heads = {re.split(r"[./:]", lab, 1)[0] for lab in labels}
+ heads = {re.split(r"[./:]", lab, maxsplit=1)[0] for lab in labels}
return any(m.group(1).split(".")[0] in heads for m in _NO_MODULE_RE.finditer(out or ""))