Skip to content

Commit c29d54a

Browse files
committed
check __slots__ isidentifier
1 parent 4457769 commit c29d54a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

crates/vm/src/builtins/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ impl PyStr {
13361336
}
13371337

13381338
#[pymethod]
1339-
fn isidentifier(&self) -> bool {
1339+
pub fn isidentifier(&self) -> bool {
13401340
let Some(s) = self.to_str() else { return false };
13411341
let mut chars = s.chars();
13421342
let is_identifier_start = chars.next().is_some_and(|c| c == '_' || is_xid_start(c));

crates/vm/src/builtins/type.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,15 @@ impl Constructor for PyType {
13781378
tuple.try_into_typed(vm)?
13791379
};
13801380

1381+
// Validate that all slots are valid identifiers
1382+
for slot in slots.iter() {
1383+
if !slot.isidentifier() {
1384+
return Err(
1385+
vm.new_type_error("__slots__ must be identifiers".to_owned())
1386+
);
1387+
}
1388+
}
1389+
13811390
// Check if __dict__ is in slots
13821391
let dict_name = "__dict__";
13831392
let has_dict = slots.iter().any(|s| s.as_str() == dict_name);

0 commit comments

Comments
 (0)