Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Count Unknown closing braces in tokenize EOF check
`$` inside an f-string interpolation is TokenKind::Unknown, so
the matching `}` is Unknown rather than Rbrace and generate_tokens
raised TokenError. Also convert &Py<PyCode> to PyObjectRef
explicitly when registering linecache.

Assisted-by: Grok:4.6
  • Loading branch information
youknowone committed Sep 21, 2026
commit 9578f019be0e3101292da438758972eb0dabf12d
7 changes: 7 additions & 0 deletions crates/stdlib/src/_tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ mod _tokenize {
.map(|t| match t.kind() {
TokenKind::Lpar | TokenKind::Lsqb | TokenKind::Lbrace => 1,
TokenKind::Rpar | TokenKind::Rsqb | TokenKind::Rbrace => -1,
// `$` inside an f-string interpolation is Unknown, and the
// matching `}` is then also Unknown rather than Rbrace.
TokenKind::Unknown => match &source[t.range()] {
"(" | "[" | "{" => 1,
")" | "]" | "}" => -1,
_ => 0,
},
_ => 0,
})
.sum();
Expand Down
7 changes: 5 additions & 2 deletions crates/vm/src/vm/python_run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Python code execution functions.

use crate::{
Py, PyRef, PyResult, VirtualMachine,
Py, PyObjectRef, PyResult, VirtualMachine,
builtins::PyCode,
compiler::{self},
scope::Scope,
Expand Down Expand Up @@ -35,7 +35,10 @@ impl VirtualMachine {
let register = linecache.get_attr("_register_code", self)?;
let source_str = self.ctx.new_str(source);
let filename = self.ctx.new_str(code.source_path().as_str());
register.call((code.to_owned().into(), source_str, filename), self)?;
register.call(
(PyObjectRef::from(code.to_owned()), source_str, filename),
self,
)?;
Ok(())
}

Expand Down
Loading