Commit d44733b1 authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #986 from Daetalus/builtin_doc

add doc to existed builtin function or method
parents fd85b564 c8f55421
This diff is collapsed.
......@@ -42,14 +42,32 @@ static Box* enable() {
return None;
}
PyDoc_STRVAR(gc_enable_doc, "enable() -> None\n"
"\n"
"Enable automatic garbage collection.\n");
PyDoc_STRVAR(gc_disable_doc, "disable() -> None\n"
"\n"
"Disable automatic garbage collection.\n");
PyDoc_STRVAR(gc_isenabled_doc, "isenabled() -> status\n"
"\n"
"Returns true if automatic garbage collection is enabled.\n");
PyDoc_STRVAR(gc_collect_doc, "collect() -> n\n"
"\n"
"Run a full collection.\n");
void setupGC() {
BoxedModule* gc_module = createModule(boxString("gc"));
gc_module->giveAttr("collect",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)gcCollect, NONE, 0), "collect"));
gc_module->giveAttr("isenabled",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)isEnabled, BOXED_BOOL, 0), "isenabled"));
gc_module->giveAttr("disable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)disable, NONE, 0), "disable"));
gc_module->giveAttr("enable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)enable, NONE, 0), "enable"));
gc_module->giveAttr("collect", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)gcCollect, NONE, 0), "collect",
gc_collect_doc));
gc_module->giveAttr("isenabled", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)isEnabled, BOXED_BOOL, 0),
"isenabled", gc_isenabled_doc));
gc_module->giveAttr(
"disable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)disable, NONE, 0), "disable", gc_disable_doc));
gc_module->giveAttr(
"enable", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)enable, NONE, 0), "enable", gc_enable_doc));
}
}
......@@ -590,6 +590,43 @@ PyObject* PyFloat_GetInfo(void) {
return floatinfo;
}
PyDoc_STRVAR(exc_info_doc, "exc_info() -> (type, value, traceback)\n\
\n\
Return information about the most recent exception caught by an except\n\
clause in the current stack frame or in an older stack frame.");
PyDoc_STRVAR(exc_clear_doc, "exc_clear() -> None\n\
\n\
Clear global information on the current exception. Subsequent calls to\n\
exc_info() will return (None,None,None) until another exception is raised\n\
in the current thread or the execution stack returns to a frame where\n\
another exception is being handled.");
PyDoc_STRVAR(exit_doc, "exit([status])\n\
\n\
Exit the interpreter by raising SystemExit(status).\n\
If the status is omitted or None, it defaults to zero (i.e., success).\n\
If the status is an integer, it will be used as the system exit status.\n\
If it is another kind of object, it will be printed and the system\n\
exit status will be one (i.e., failure).");
PyDoc_STRVAR(getdefaultencoding_doc, "getdefaultencoding() -> string\n\
\n\
Return the current default string encoding used by the Unicode \n\
implementation.");
PyDoc_STRVAR(getfilesystemencoding_doc, "getfilesystemencoding() -> string\n\
\n\
Return the encoding used to convert Unicode filenames in\n\
operating system filenames.");
PyDoc_STRVAR(getrecursionlimit_doc, "getrecursionlimit()\n\
\n\
Return the current value of the recursion limit, the maximum depth\n\
of the Python interpreter stack. This limit prevents infinite\n\
recursion from causing an overflow of the C stack and crashing Python.");
void setupSys() {
sys_modules_dict = new BoxedDict();
gc::registerPermanentRoot(sys_modules_dict);
......@@ -611,12 +648,12 @@ void setupSys() {
sys_module->giveAttr("__stdin__", sys_module->getattr(internStringMortal("stdin")));
sys_module->giveAttr("__stderr__", sys_module->getattr(internStringMortal("stderr")));
sys_module->giveAttr(
"exc_info", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcInfo, BOXED_TUPLE, 0), "exc_info"));
sys_module->giveAttr("exc_clear",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcClear, NONE, 0), "exc_clear"));
sys_module->giveAttr("exc_info", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcInfo, BOXED_TUPLE, 0),
"exc_info", exc_info_doc));
sys_module->giveAttr("exc_clear", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExcClear, NONE, 0),
"exc_clear", exc_clear_doc));
sys_module->giveAttr("exit", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysExit, NONE, 1, false, false),
"exit", { None }));
"exit", { None }, NULL, exit_doc));
sys_module->giveAttr("warnoptions", new BoxedList());
sys_module->giveAttr("py3kwarning", False);
......@@ -628,17 +665,17 @@ void setupSys() {
sys_module->giveAttr("_getframe",
new BoxedFunction(boxRTFunction((void*)sysGetFrame, UNKNOWN, 1, false, false), { NULL }));
sys_module->giveAttr(
"getdefaultencoding",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetDefaultEncoding, STR, 0), "getdefaultencoding"));
sys_module->giveAttr("getdefaultencoding",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetDefaultEncoding, STR, 0),
"getdefaultencoding", getdefaultencoding_doc));
sys_module->giveAttr("getfilesystemencoding",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetFilesystemEncoding, STR, 0),
"getfilesystemencoding"));
"getfilesystemencoding", getfilesystemencoding_doc));
sys_module->giveAttr(
"getrecursionlimit",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetRecursionLimit, UNKNOWN, 0), "getrecursionlimit"));
sys_module->giveAttr("getrecursionlimit",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetRecursionLimit, UNKNOWN, 0),
"getrecursionlimit", getrecursionlimit_doc));
sys_module->giveAttr("meta_path", new BoxedList());
sys_module->giveAttr("path_hooks", new BoxedList());
......
......@@ -1027,7 +1027,7 @@ static void floatFormatInit() {
}
// ported pretty directly from cpython
Box* floatGetFormat(BoxedClass* v, Box* arg) {
Box* floatGetFormat(Box* arg) {
char* s;
float_format_type r;
......@@ -1692,9 +1692,8 @@ void setupFloat() {
float_cls->giveAttr("imag", new (pyston_getset_cls) BoxedGetsetDescriptor(float0, NULL, NULL));
float_cls->giveAttr("conjugate", new BoxedFunction(boxRTFunction((void*)floatConjugate, BOXED_FLOAT, 1)));
float_cls->giveAttr("__getformat__",
new BoxedClassmethod(new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)floatGetFormat, STR, 2), "__getformat__", floatGetFormatDoc)));
float_cls->giveAttr("__getformat__", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)floatGetFormat, STR, 1),
"__getformat__", floatGetFormatDoc));
for (auto& md : float_methods) {
float_cls->giveAttr(md.ml_name, new BoxedMethodDescriptor(&md, float_cls));
......
......@@ -963,6 +963,30 @@ Box* impIsFrozen(Box* name) {
return False;
}
PyDoc_STRVAR(find_module_doc, "find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\
Search for a module. If path is omitted or None, search for a\n\
built-in, frozen or special module and continue search in sys.path.\n\
The module name cannot contain '.'; to search for a submodule of a\n\
package, pass the submodule name and the package's __path__.");
PyDoc_STRVAR(load_module_doc, "load_module(name, file, filename, (suffix, mode, type)) -> module\n\
Load a module, given information returned by find_module().\n\
The module name must include the full package name, if any.");
PyDoc_STRVAR(get_suffixes_doc, "get_suffixes() -> [(suffix, mode, type), ...]\n\
Return a list of (suffix, mode, type) tuples describing the files\n\
that find_module() looks for.");
PyDoc_STRVAR(acquire_lock_doc, "acquire_lock() -> None\n\
Acquires the interpreter's import lock for the current thread.\n\
This lock should be used by import hooks to ensure thread-safety\n\
when importing modules.\n\
On platforms without threads, this function does nothing.");
PyDoc_STRVAR(release_lock_doc, "release_lock() -> None\n\
Release the interpreter's import lock.\n\
On platforms without threads, this function does nothing.");
void setupImport() {
BoxedModule* imp_module
= createModule(boxString("imp"), NULL, "'This module provides the components needed to build your own\n"
......@@ -980,17 +1004,19 @@ void setupImport() {
"__init__", new BoxedFunction(boxRTFunction((void*)nullImporterInit, NONE, 2, false, false), { None }));
null_importer_cls->giveAttr("find_module", new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)nullImporterFindModule, NONE, 2, false, false),
"find_module", { None }));
"find_module", { None }, NULL, find_module_doc));
null_importer_cls->freeze();
imp_module->giveAttr("NullImporter", null_importer_cls);
CLFunction* find_module_func
= boxRTFunction((void*)impFindModule, UNKNOWN, 2, false, false, ParamNames({ "name", "path" }, "", ""));
imp_module->giveAttr("find_module", new BoxedBuiltinFunctionOrMethod(find_module_func, "find_module", { None }));
imp_module->giveAttr("find_module", new BoxedBuiltinFunctionOrMethod(find_module_func, "find_module", { None },
NULL, find_module_doc));
CLFunction* load_module_func = boxRTFunction((void*)impLoadModule, UNKNOWN, 4,
ParamNames({ "name", "file", "pathname", "description" }, "", ""));
imp_module->giveAttr("load_module", new BoxedBuiltinFunctionOrMethod(load_module_func, "load_module"));
imp_module->giveAttr("load_module",
new BoxedBuiltinFunctionOrMethod(load_module_func, "load_module", load_module_doc));
imp_module->giveAttr("load_source",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impLoadSource, UNKNOWN, 3, false, false),
"load_source", { NULL }));
......@@ -999,12 +1025,13 @@ void setupImport() {
ParamNames({ "name", "pathname", "file" }, "", ""));
imp_module->giveAttr("load_dynamic", new BoxedBuiltinFunctionOrMethod(load_dynamic_func, "load_dynamic", { None }));
imp_module->giveAttr("get_suffixes", new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)impGetSuffixes, UNKNOWN, 0), "get_suffixes"));
imp_module->giveAttr("get_suffixes",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impGetSuffixes, UNKNOWN, 0),
"get_suffixes", get_suffixes_doc));
imp_module->giveAttr("acquire_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impAcquireLock, NONE, 0),
"acquire_lock"));
"acquire_lock", acquire_lock_doc));
imp_module->giveAttr("release_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impReleaseLock, NONE, 0),
"release_lock"));
"release_lock", release_lock_doc));
imp_module->giveAttr("new_module",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impNewModule, MODULE, 1), "new_module"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment