Skip to content

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

@aisk aisk commented Feb 28, 2026

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 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.

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

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

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 🥲

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants