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

Commit883a494

Browse files
Merge pull requestRustPython#598 from palaviv/dir-module
Fix module dir
2 parentsa264017 +2d31e35 commit883a494

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

‎tests/snippets/builtin_dir.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
classA:
3+
deftest():
4+
pass
5+
6+
a=A()
7+
8+
assert"test"indir(a)
9+
10+
importsocket
11+
12+
assert"AF_INET"indir(socket)

‎vm/src/obj/objtype.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::objdict;
22
usesuper::objstr;
33
usesuper::objtype;// Required for arg_check! to use isinstance
44
usecrate::pyobject::{
5-
AttributeProtocol,IdProtocol,PyAttributes,PyContext,PyFuncArgs,PyObject,PyObjectPayload,
6-
PyObjectRef,PyResult,TypeProtocol,
5+
AttributeProtocol,DictProtocol,IdProtocol,PyAttributes,PyContext,PyFuncArgs,PyObject,
6+
PyObjectPayload,PyObjectRef,PyResult,TypeProtocol,
77
};
88
usecrate::vm::VirtualMachine;
99
use std::cell::RefCell;
@@ -277,6 +277,13 @@ pub fn get_attributes(obj: &PyObjectRef) -> PyAttributes {
277277
attributes.insert(name.to_string(), value.clone());
278278
}
279279
}
280+
281+
// Get module attributes:
282+
ifletPyObjectPayload::Module{ref scope, ..} =&obj.payload{
283+
for(name, value)in scope.locals.get_key_value_pairs().iter(){
284+
attributes.insert(objstr::get_value(name).to_string(), value.clone());
285+
}
286+
}
280287
attributes
281288
}
282289

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp