File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff 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) ) ;
Original file line number Diff line number Diff 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) ;
You can’t perform that action at this time.
0 commit comments