pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/go-python/gpython/pull/254/files

/github.githubassets.com/assets/code-34e10031edc15af1.css" /> stdlib: Add quit and exit by aisk · Pull Request #254 · go-python/gpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions stdlib/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func init() {
py.MustNewMethod("divmod", builtin_divmod, 0, divmod_doc),
py.MustNewMethod("eval", py.InternalMethodEval, 0, eval_doc),
py.MustNewMethod("exec", py.InternalMethodExec, 0, exec_doc),
py.MustNewMethod("exit", builtin_exit, 0, exit_doc),
// py.MustNewMethod("format", builtin_format, 0, format_doc),
py.MustNewMethod("getattr", builtin_getattr, 0, getattr_doc),
py.MustNewMethod("globals", py.InternalMethodGlobals, 0, globals_doc),
Expand All @@ -61,6 +62,7 @@ func init() {
py.MustNewMethod("ord", builtin_ord, 0, ord_doc),
py.MustNewMethod("pow", builtin_pow, 0, pow_doc),
py.MustNewMethod("print", builtin_print, 0, print_doc),
py.MustNewMethod("quit", builtin_quit, 0, quit_doc),
py.MustNewMethod("repr", builtin_repr, 0, repr_doc),
py.MustNewMethod("round", builtin_round, 0, round_doc),
py.MustNewMethod("setattr", builtin_setattr, 0, setattr_doc),
Expand Down Expand Up @@ -1262,6 +1264,35 @@ func builtin_input(self py.Object, args py.Tuple) (py.Object, error) {
return line, nil
}

const exit_doc = `exit([status])

Exit the interpreter by raising SystemExit(status).`

const quit_doc = `quit([status])

Alias for exit().`

func builtin_exit(self py.Object, args py.Tuple) (py.Object, error) {
return builtinExit("exit", args)
}

func builtin_quit(self py.Object, args py.Tuple) (py.Object, error) {
return builtinExit("quit", args)
}

func builtinExit(name string, args py.Tuple) (py.Object, error) {
var exitCode py.Object
err := py.UnpackTuple(args, nil, name, 0, 1, &exitCode)
if err != nil {
return nil, err
}
exc, err := py.ExceptionNew(py.SystemExit, args, nil)
if err != nil {
return nil, err
}
return nil, exc.(*py.Exception)
}

const locals_doc = `locals() -> dictionary

Update and return a dictionary containing the current scope's local variables.`
Expand Down
9 changes: 9 additions & 0 deletions stdlib/builtin/tests/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
assert exec("b = a+100", glob) == None
assert glob["b"] == 200

doc="exit/quit"
assertRaises(SystemExit, exit)
assertRaises(SystemExit, exit, 0)
assertRaises(SystemExit, exit, 3)
assertRaises(SystemExit, quit)
assertRaises(SystemExit, quit, "bye")
assertRaises(TypeError, exit, 1, 2)
assertRaises(TypeError, quit, 1, 2)

doc="getattr"
class C:
def __init__(self):
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy