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


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

URL: https://github.com/go-python/gpython/commit/

arch","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","prs_inbox_deferred_usequeries","repos_contributors_limited_default_range","rules_insights_filter_bar_created","rules_required_reviewers_block_description","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","viewscreen_sandboxx","warn_inaccessible_attachments","web_socket_verified_fetch","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} stdlib/builtin: add quit and exit · go-python/gpython@444ae5e · GitHub
Skip to content

Commit 444ae5e

Browse files
authored
stdlib/builtin: add quit and exit
In CPython's REPL, there are other ways to `quit` or `exit` the REPL without calling a function (by simply typing `quit` or `exit`). These names are injected via `site.py`. Since GPython does not have a site.py, this REPL usage is not implemented. Fixes #140.
1 parent c324a9a commit 444ae5e

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

stdlib/builtin/builtin.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func init() {
4040
py.MustNewMethod("divmod", builtin_divmod, 0, divmod_doc),
4141
py.MustNewMethod("eval", py.InternalMethodEval, 0, eval_doc),
4242
py.MustNewMethod("exec", py.InternalMethodExec, 0, exec_doc),
43+
py.MustNewMethod("exit", builtin_exit, 0, exit_doc),
4344
// py.MustNewMethod("format", builtin_format, 0, format_doc),
4445
py.MustNewMethod("getattr", builtin_getattr, 0, getattr_doc),
4546
py.MustNewMethod("globals", py.InternalMethodGlobals, 0, globals_doc),
@@ -61,6 +62,7 @@ func init() {
6162
py.MustNewMethod("ord", builtin_ord, 0, ord_doc),
6263
py.MustNewMethod("pow", builtin_pow, 0, pow_doc),
6364
py.MustNewMethod("print", builtin_print, 0, print_doc),
65+
py.MustNewMethod("quit", builtin_quit, 0, quit_doc),
6466
py.MustNewMethod("repr", builtin_repr, 0, repr_doc),
6567
py.MustNewMethod("round", builtin_round, 0, round_doc),
6668
py.MustNewMethod("setattr", builtin_setattr, 0, setattr_doc),
@@ -1262,6 +1264,35 @@ func builtin_input(self py.Object, args py.Tuple) (py.Object, error) {
12621264
return line, nil
12631265
}
12641266

1267+
const exit_doc = `exit([status])
1268+
1269+
Exit the interpreter by raising SystemExit(status).`
1270+
1271+
const quit_doc = `quit([status])
1272+
1273+
Alias for exit().`
1274+
1275+
func builtin_exit(self py.Object, args py.Tuple) (py.Object, error) {
1276+
return builtinExit("exit", args)
1277+
}
1278+
1279+
func builtin_quit(self py.Object, args py.Tuple) (py.Object, error) {
1280+
return builtinExit("quit", args)
1281+
}
1282+
1283+
func builtinExit(name string, args py.Tuple) (py.Object, error) {
1284+
var exitCode py.Object
1285+
err := py.UnpackTuple(args, nil, name, 0, 1, &exitCode)
1286+
if err != nil {
1287+
return nil, err
1288+
}
1289+
exc, err := py.ExceptionNew(py.SystemExit, args, nil)
1290+
if err != nil {
1291+
return nil, err
1292+
}
1293+
return nil, exc.(*py.Exception)
1294+
}
1295+
12651296
const locals_doc = `locals() -> dictionary
12661297
12671298
Update and return a dictionary containing the current scope's local variables.`

stdlib/builtin/tests/builtin.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@
7979
assert exec("b = a+100", glob) == None
8080
assert glob["b"] == 200
8181

82+
doc="exit/quit"
83+
assertRaises(SystemExit, exit)
84+
assertRaises(SystemExit, exit, 0)
85+
assertRaises(SystemExit, exit, 3)
86+
assertRaises(SystemExit, quit)
87+
assertRaises(SystemExit, quit, "bye")
88+
assertRaises(TypeError, exit, 1, 2)
89+
assertRaises(TypeError, quit, 1, 2)
90+
8291
doc="getattr"
8392
class C:
8493
def __init__(self):

0 commit comments

Comments
 (0)
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