Skip to content

Commit 61cbb49

Browse files
committed
Added __doc__ for sys module
1 parent 3dc2ab9 commit 61cbb49

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ __pycache__
77
.repl_history.txt
88
.vscode
99
wasm-pack.log
10+
.idea/

tests/snippets/sysmod.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
3+
print(sys.argv)
4+
assert sys.argv[0].endswith('.py')
5+
assert sys.__doc__ == "This module provides access to some objects used or maintained by the\ninterpreter and to functions that interact strongly with the interpreter.\n\nDynamic objects:\n\nargv -- command line arguments; argv[0] is the script pathname if known\npath -- module search path; path[0] is the script directory, else ''\nmodules -- dictionary of loaded modules\n\ndisplayhook -- called to show results in an interactive session\nexcepthook -- called to handle any uncaught exception other than SystemExit\n To customize printing in an interactive session or to install a custom\n top-level exception handler, assign other functions to replace these.\n\nstdin -- standard input file object; used by input()\nstdout -- standard output file object; used by print()\nstderr -- standard error object; used for error messages\n By assigning other file objects (or objects that behave like files)\n to these, it is possible to redirect all of the interpreter's I/O.\n\nlast_type -- type of last uncaught exception\nlast_value -- value of last uncaught exception\nlast_traceback -- traceback of last uncaught exception\n These three are only available in an interactive session after a\n traceback has been printed.\n\nStatic objects:\n\nbuiltin_module_names -- tuple of module names built into this interpreter\ncopyright -- copyright notice pertaining to this interpreter\nexec_prefix -- prefix used to find the machine-specific Python library\nexecutable -- absolute path of the executable binary of the Python interpreter\nfloat_info -- a struct sequence with information about the float implementation.\nfloat_repr_style -- string indicating the style of repr() output for floats\nhash_info -- a struct sequence with information about the hash algorithm.\nhexversion -- version information encoded as a single integer\nimplementation -- Python implementation information.\nint_info -- a struct sequence with information about the int implementation.\nmaxsize -- the largest supported length of containers.\nmaxunicode -- the value of the largest Unicode code point\nplatform -- platform identifier\nprefix -- prefix used to find the Python library\nthread_info -- a struct sequence with information about the thread implementation.\nversion -- the version of this interpreter as a string\nversion_info -- version information as a named tuple\n__stdin__ -- the original stdin; don't touch!\n__stdout__ -- the original stdout; don't touch!\n__stderr__ -- the original stderr; don't touch!\n__displayhook__ -- the original displayhook; don't touch!\n__excepthook__ -- the original excepthook; don't touch!\n\nFunctions:\n\ndisplayhook() -- print an object to the screen, and save it in builtins._\nexcepthook() -- print an exception and its traceback to sys.stderr\nexc_info() -- return thread-safe information about the current exception\nexit() -- exit the interpreter by raising SystemExit\ngetdlopenflags() -- returns flags to be used for dlopen() calls\ngetprofile() -- get the global profiling function\ngetrefcount() -- return the reference count for an object (plus one :-)\ngetrecursionlimit() -- return the max recursion depth for the interpreter\ngetsizeof() -- return the size of an object in bytes\ngettrace() -- get the global debug tracing function\nsetcheckinterval() -- control how often the interpreter checks for events\nsetdlopenflags() -- set the flags to be used for dlopen() calls\nsetprofile() -- set the global profiling function\nsetrecursionlimit() -- set the max recursion depth for the interpreter\nsettrace() -- set the global debug tracing function\n"

tests/snippets/sysmod_argv.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

vm/src/sysmodule.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,75 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
5353
let modules = ctx.new_dict();
5454

5555
let sys_name = "sys";
56+
let sys_doc = "This module provides access to some objects used or maintained by the
57+
interpreter and to functions that interact strongly with the interpreter.
58+
59+
Dynamic objects:
60+
61+
argv -- command line arguments; argv[0] is the script pathname if known
62+
path -- module search path; path[0] is the script directory, else ''
63+
modules -- dictionary of loaded modules
64+
65+
displayhook -- called to show results in an interactive session
66+
excepthook -- called to handle any uncaught exception other than SystemExit
67+
To customize printing in an interactive session or to install a custom
68+
top-level exception handler, assign other functions to replace these.
69+
70+
stdin -- standard input file object; used by input()
71+
stdout -- standard output file object; used by print()
72+
stderr -- standard error object; used for error messages
73+
By assigning other file objects (or objects that behave like files)
74+
to these, it is possible to redirect all of the interpreter's I/O.
75+
76+
last_type -- type of last uncaught exception
77+
last_value -- value of last uncaught exception
78+
last_traceback -- traceback of last uncaught exception
79+
These three are only available in an interactive session after a
80+
traceback has been printed.
81+
82+
Static objects:
83+
84+
builtin_module_names -- tuple of module names built into this interpreter
85+
copyright -- copyright notice pertaining to this interpreter
86+
exec_prefix -- prefix used to find the machine-specific Python library
87+
executable -- absolute path of the executable binary of the Python interpreter
88+
float_info -- a struct sequence with information about the float implementation.
89+
float_repr_style -- string indicating the style of repr() output for floats
90+
hash_info -- a struct sequence with information about the hash algorithm.
91+
hexversion -- version information encoded as a single integer
92+
implementation -- Python implementation information.
93+
int_info -- a struct sequence with information about the int implementation.
94+
maxsize -- the largest supported length of containers.
95+
maxunicode -- the value of the largest Unicode code point
96+
platform -- platform identifier
97+
prefix -- prefix used to find the Python library
98+
thread_info -- a struct sequence with information about the thread implementation.
99+
version -- the version of this interpreter as a string
100+
version_info -- version information as a named tuple
101+
__stdin__ -- the original stdin; don't touch!
102+
__stdout__ -- the original stdout; don't touch!
103+
__stderr__ -- the original stderr; don't touch!
104+
__displayhook__ -- the original displayhook; don't touch!
105+
__excepthook__ -- the original excepthook; don't touch!
106+
107+
Functions:
108+
109+
displayhook() -- print an object to the screen, and save it in builtins._
110+
excepthook() -- print an exception and its traceback to sys.stderr
111+
exc_info() -- return thread-safe information about the current exception
112+
exit() -- exit the interpreter by raising SystemExit
113+
getdlopenflags() -- returns flags to be used for dlopen() calls
114+
getprofile() -- get the global profiling function
115+
getrefcount() -- return the reference count for an object (plus one :-)
116+
getrecursionlimit() -- return the max recursion depth for the interpreter
117+
getsizeof() -- return the size of an object in bytes
118+
gettrace() -- get the global debug tracing function
119+
setcheckinterval() -- control how often the interpreter checks for events
120+
setdlopenflags() -- set the flags to be used for dlopen() calls
121+
setprofile() -- set the global profiling function
122+
setrecursionlimit() -- set the max recursion depth for the interpreter
123+
settrace() -- set the global debug tracing function
124+
";
56125
let sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None));
57126

58127
ctx.set_item(&modules, sys_name, sys_mod.clone());
@@ -65,6 +134,7 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
65134
ctx.set_item(&sys_mod, "path", path);
66135
ctx.set_item(&sys_mod, "ps1", ctx.new_str(">>>>> ".to_string()));
67136
ctx.set_item(&sys_mod, "ps2", ctx.new_str("..... ".to_string()));
137+
ctx.set_item(&sys_mod, "__doc__", ctx.new_str(sys_doc.to_string()));
68138
ctx.set_item(&sys_mod, "_getframe", ctx.new_rustfunc(getframe));
69139

70140
sys_mod

0 commit comments

Comments
 (0)