@@ -7,6 +7,7 @@ https://github.com/python/cpython/blob/50b48572d9a90c5bb36e2bef6179548ea927a35a/
7
7
*/
8
8
9
9
use crate :: function:: PyFuncArgs ;
10
+ use crate :: obj:: objstr;
10
11
use crate :: obj:: objtype:: PyClass ;
11
12
use crate :: pyobject:: {
12
13
DictProtocol , PyContext , PyObject , PyObjectRef , PyResult , PyValue , TypeProtocol ,
@@ -75,7 +76,11 @@ fn super_getattribute(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
75
76
return Ok ( vm. ctx . new_bound_method ( item, inst. clone ( ) ) ) ;
76
77
}
77
78
}
78
- Err ( vm. new_attribute_error ( format ! ( "{} has no attribute '{}'" , inst, name_str) ) )
79
+ Err ( vm. new_attribute_error ( format ! (
80
+ "{} has no attribute '{}'" ,
81
+ inst,
82
+ objstr:: get_value( name_str)
83
+ ) ) )
79
84
}
80
85
_ => panic ! ( "not Class" ) ,
81
86
}
@@ -94,14 +99,31 @@ fn super_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
94
99
return Err ( vm. new_type_error ( format ! ( "{:?} is not a subtype of super" , cls) ) ) ;
95
100
}
96
101
102
+ // Get the bound object:
103
+ let py_obj = if let Some ( obj) = py_obj {
104
+ obj. clone ( )
105
+ } else {
106
+ let frame = vm. current_frame ( ) ;
107
+ if let Some ( first_arg) = frame. code . arg_names . get ( 0 ) {
108
+ match vm. get_locals ( ) . get_item ( first_arg) {
109
+ Some ( obj) => obj. clone ( ) ,
110
+ _ => {
111
+ return Err ( vm
112
+ . new_type_error ( format ! ( "super arguement {} was not supplied" , first_arg) ) ) ;
113
+ }
114
+ }
115
+ } else {
116
+ return Err ( vm. new_type_error (
117
+ "super must be called with 1 argument or from inside class method" . to_string ( ) ,
118
+ ) ) ;
119
+ }
120
+ } ;
121
+
97
122
// Get the type:
98
123
let py_type = if let Some ( ty) = py_type {
99
124
ty. clone ( )
100
125
} else {
101
- match vm. get_locals ( ) . get_item ( "self" ) {
102
- Some ( obj) => obj. typ ( ) . clone ( ) ,
103
- _ => panic ! ( "No self" ) ,
104
- }
126
+ py_obj. typ ( ) . clone ( )
105
127
} ;
106
128
107
129
// Check type argument:
@@ -113,16 +135,6 @@ fn super_new(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
113
135
) ) ) ;
114
136
}
115
137
116
- // Get the bound object:
117
- let py_obj = if let Some ( obj) = py_obj {
118
- obj. clone ( )
119
- } else {
120
- match vm. get_locals ( ) . get_item ( "self" ) {
121
- Some ( obj) => obj,
122
- _ => panic ! ( "No self" ) ,
123
- }
124
- } ;
125
-
126
138
// Check obj type:
127
139
if !( objtype:: isinstance ( & py_obj, & py_type) || objtype:: issubclass ( & py_obj, & py_type) ) {
128
140
return Err ( vm. new_type_error (
0 commit comments