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
check __slots__ isidentifier
  • Loading branch information
youknowone committed Dec 27, 2025
commit c29d54a809f0466965f91ea1b538e812969382fd
2 changes: 1 addition & 1 deletion crates/vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ impl PyStr {
}

#[pymethod]
fn isidentifier(&self) -> bool {
pub fn isidentifier(&self) -> bool {
let Some(s) = self.to_str() else { return false };
let mut chars = s.chars();
let is_identifier_start = chars.next().is_some_and(|c| c == '_' || is_xid_start(c));
Expand Down
9 changes: 9 additions & 0 deletions crates/vm/src/builtins/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,15 @@ impl Constructor for PyType {
tuple.try_into_typed(vm)?
};

// Validate that all slots are valid identifiers
for slot in slots.iter() {
if !slot.isidentifier() {
return Err(
vm.new_type_error("__slots__ must be identifiers".to_owned())
);
}
}

// Check if __dict__ is in slots
let dict_name = "__dict__";
let has_dict = slots.iter().any(|s| s.as_str() == dict_name);
Expand Down
Loading