Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit830389f

Browse files
authored
implement dir for ByObjectRef (RustPython#5088)
1 parent2c3dbb5 commit830389f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

‎vm/src/builtins/object.rs‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
usesuper::{PyDict,PyDictRef,PyList,PyStr,PyStrRef,PyType,PyTypeRef};
1+
usesuper::{PyDictRef,PyList,PyStr,PyStrRef,PyType,PyTypeRef};
22
usecrate::common::hash::PyHash;
33
usecrate::{
44
class::PyClassImpl,
@@ -252,22 +252,7 @@ impl PyBaseObject {
252252

253253
#[pymethod(magic)]
254254
pubfndir(obj:PyObjectRef,vm:&VirtualMachine) ->PyResult<PyList>{
255-
let attributes = obj.class().get_attributes();
256-
257-
let dict =PyDict::from_attributes(attributes, vm)?.into_ref(&vm.ctx);
258-
259-
// Get instance attributes:
260-
ifletSome(object_dict) = obj.dict(){
261-
vm.call_method(
262-
dict.as_object(),
263-
identifier!(vm, update).as_str(),
264-
(object_dict,),
265-
)?;
266-
}
267-
268-
let attributes:Vec<_> = dict.into_iter().map(|(k, _v)| k).collect();
269-
270-
Ok(PyList::from(attributes))
255+
obj.dir(vm)
271256
}
272257

273258
#[pymethod(magic)]

‎vm/src/protocol/object.rs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
44
usecrate::{
55
builtins::{
6-
pystr::AsPyStr,PyBytes,PyDict,PyDictRef,PyGenericAlias,PyInt,PyStr,PyStrRef,
6+
pystr::AsPyStr,PyBytes,PyDict,PyDictRef,PyGenericAlias,PyInt,PyList,PyStr,PyStrRef,
77
PyTuple,PyTupleRef,PyType,PyTypeRef,
88
},
99
bytesinner::ByteInnerNewOptions,
1010
common::{hash::PyHash, str::to_ascii},
1111
convert::{ToPyObject,ToPyResult},
1212
dictdatatype::DictKey,
1313
function::{Either,OptionalArg,PyArithmeticValue,PySetterValue},
14+
object::PyPayload,
1415
protocol::{PyIter,PyMapping,PySequence},
1516
types::{Constructor,PyComparisonOp},
1617
AsObject,Py,PyObject,PyObjectRef,PyResult,TryFromObject,VirtualMachine,
@@ -62,6 +63,23 @@ impl PyObjectRef {
6263
}
6364

6465
// PyObject *PyObject_Dir(PyObject *o)
66+
pubfndir(self,vm:&VirtualMachine) ->PyResult<PyList>{
67+
let attributes =self.class().get_attributes();
68+
69+
let dict =PyDict::from_attributes(attributes, vm)?.into_ref(&vm.ctx);
70+
71+
ifletSome(object_dict) =self.dict(){
72+
vm.call_method(
73+
dict.as_object(),
74+
identifier!(vm, update).as_str(),
75+
(object_dict,),
76+
)?;
77+
}
78+
79+
let attributes:Vec<_> = dict.into_iter().map(|(k, _v)| k).collect();
80+
81+
Ok(PyList::from(attributes))
82+
}
6583
}
6684

6785
implPyObject{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp