FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

stdlib: Add quit and exit by aisk · Pull Request #254 · go-python/gpython · GitHub

stdlib: Add quit and exit - #254

Merged
sbinet merged 1 commit into
go-python:mainfrom
aisk:exit-quit
Mar 2, 2026
Merged

stdlib: Add quit and exit#254
sbinet merged 1 commit into
go-python:mainfrom
aisk:exit-quit

Conversation

aisk commented Feb 28, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

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

Close: #140

sbinet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

FYI, we have a little discrepancy w/ CPython (3.14) here:

$> python
>>> exit(False)
$> echo $?
0

$> python
>>> exit(True)
$> echo $?
1

compared to:

$> gpython
>>> exit(False)
False
$> echo $?
1

$> gpython
>>> exit(True)
True
$> echo $?
1

(note the extraneous printouts and the different exit codes.)

sbinet merged commit 444ae5e into go-python:main Mar 2, 2026
6 checks passed
aisk deleted the exit-quit branch March 2, 2026 13:05

aisk commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

In CPython, bool type implemented the __index__ method, so True will be treated as 1 and False will be treated as 0 when a number like object is required. In GPython, we don't have this method implemented, thus the difference.

❯ python3
Python 3.14.3 (main, Feb  3 2026, 15:32:20) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True.__index__()
1
>>>

gpython on  main [?] via 🐹 v1.26.0 via 🐍 v3.14.3 took 10s
❯ ./gpython
Python 3.4.0 (none, unknown)
[Gpython dev]
- os/arch: darwin/amd64
- go version: go1.26.0
>>> True.__index__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: 'unknown bound method type for "__index__": func() (py.Int, error)'
>>>

aisk commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

In CPython, bool type implemented the __index__ method, so True will be treated as 1 and False will be treated as 0 when a number like object is required. In GPython, we don't have this method implemented, thus the difference.

❯ python3
Python 3.14.3 (main, Feb  3 2026, 15:32:20) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> True.__index__()
1
>>>

gpython on  main [?] via 🐹 v1.26.0 via 🐍 v3.14.3 took 10s
❯ ./gpython
Python 3.4.0 (none, unknown)
[Gpython dev]
- os/arch: darwin/amd64
- go version: go1.26.0
>>> True.__index__()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: 'unknown bound method type for "__index__": func() (py.Int, error)'
>>>

This is not correct, after #255, the behavior is still not exactly like CPython 🥲

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No functional exit function.

2 participants


Back | FazBrowse Home | New Git URL