Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

python: re-check aliased calls whose literal name matches PURE_CALLS

RRFZ8d70ee59322b
diff --git a/src/python.rs b/src/python.rs
index 36fbcdb..d8226b2 100644
--- a/src/python.rs
+++ b/src/python.rs
@@ -1079,7 +1079,8 @@ sys.exit(1 if fails else 0)
def impure_listdir(p: str) -> int:\n return len(os.listdir(p)) if False else len(p)\n\n\
def impure_now(n: int) -> int:\n return datetime.datetime.now().year + n\n\n\
def impure_uuid4(n: int) -> int:\n return len(str(uuid.uuid4())) + n\n\n\
- def impure_urlopen(u: str) -> int:\n if False:\n urllib.request.urlopen(u)\n return len(u)\n",
+ def impure_urlopen(u: str) -> int:\n if False:\n urllib.request.urlopen(u)\n return len(u)\n\n\
+ def impure_aliased_time() -> float:\n import time as datetime\n return datetime.time()\n",
)
.unwrap();
fs::write(
@@ -1097,7 +1098,8 @@ sys.exit(1 if fails else 0)
\x20 work.impure_listdir('.')\n\
\x20 work.impure_now(i)\n\
\x20 work.impure_uuid4(i)\n\
- \x20 work.impure_urlopen('https://example.com')\n",
+ \x20 work.impure_urlopen('https://example.com')\n\
+ \x20 work.impure_aliased_time()\n",
)
.unwrap();
let scanned = crate::pipeline::scan(&dir, vec![python.into(), "app.py".into()], None);
@@ -1117,6 +1119,7 @@ sys.exit(1 if fails else 0)
("impure_now", "not deterministic: datetime.datetime.now"),
("impure_uuid4", "not deterministic: uuid.uuid4"),
("impure_urlopen", "does I/O: urllib.request.urlopen"),
+ ("impure_aliased_time", "not deterministic: time.time"),
] {
let h = by_name(impure);
assert!(!h.portable(), "{impure} must stay blocked");
diff --git a/src/python/runner.py b/src/python/runner.py
index 88a4903..6491fc9 100644
--- a/src/python/runner.py
+++ b/src/python/runner.py
@@ -617,7 +617,11 @@ def describe(path, line, name, entry, base):
# the same calls through an import: `sp.run` is subprocess.run, `system` is os.system
for target, origins in resolved_calls(node, module_level_names):
head = target[0]
- if (head in IO_NAMES if len(target) == 1 else head in IO_MODULES or head in NONDET_MODULES):
+ if (
+ head in IO_NAMES
+ if len(target) == 1
+ else (head in IO_MODULES or head in NONDET_MODULES) and not is_pure_call(".".join(target))
+ ):
continue # already caught by name
for origin in origins:
effect = origin and resolved_effect(list(origin) + target[1:])