Skip to content

stdlib: Add quit and exit#254

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

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

Conversation

@aisk
Copy link
Contributor

@aisk aisk commented Feb 28, 2026

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

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

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

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 sbinet merged commit 444ae5e into go-python:main Mar 2, 2026
6 checks passed
@aisk aisk deleted the exit-quit branch March 2, 2026 13:05
@aisk
Copy link
Contributor Author

aisk commented Mar 2, 2026

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
Copy link
Contributor Author

aisk commented Mar 2, 2026

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 🥲

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