Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_pyrepl.test_exposed_globals_in_repl failure #121359

Open
smontanaro opened this issue Jul 4, 2024 · 5 comments
Open

test_pyrepl.test_exposed_globals_in_repl failure #121359

smontanaro opened this issue Jul 4, 2024 · 5 comments
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@smontanaro
Copy link
Contributor

smontanaro commented Jul 4, 2024

Bug report

Bug description:

I'm seeing this on a Dell laptop running XUbuntu 22.04 and MacBook Pro M1 running MacOS 14.5. In both cases, Python was built on main with the following sequence:

git fetch --all
git pull
git clean -fdx
./configure
nice make -j test

On the Mac, I also tested on the 3.13 branch and see the same failure (same out as below, save for the printed interpreter version details).

Dell:

======================================================================
FAIL: test_exposed_globals_in_repl (test.test_pyrepl.test_pyrepl.TestMain.test_exposed_globals_in_repl)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/skip/src/python/cpython/Lib/test/support/__init__.py", line 2622, in wrapper
    return func(*args, **kwargs)
  File "/home/skip/src/python/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 868, in test_exposed_globals_in_repl
    self.assertTrue(case1 or case2 or case3 or case4, output)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true : sorted(dir())
exit

Python 3.14.0a0 (heads/main:19d1e43e43d, Jul  4 2024, 06:49:38) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.


>>> 
>>> s
>>> so
>>> sor
>>> sort
>>> sorte
>>> sorted

>>> sorted(
>>> sorted(d
>>> sorted(di
>>> sorted(dir
>>> sorted(dir(
>>> sorted(dir()
>>> sorted(dir())




['__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__ior__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__ror__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']


>>> 
>>> e
>>> ex


>>> exi



>>> exit





Mac:

======================================================================
FAIL: test_exposed_globals_in_repl (test.test_pyrepl.test_pyrepl.TestMain.test_exposed_globals_in_repl)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/skip/src/python/cpython/Lib/test/support/__init__.py", line 2622, in wrapper
    return func(*args, **kwargs)
  File "/Users/skip/src/python/cpython/Lib/test/test_pyrepl/test_pyrepl.py", line 868, in test_exposed_globals_in_repl
    self.assertTrue(case1 or case2 or case3 or case4, output)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true : sorted(dir())
exit

Python 3.14.0a0 (heads/main:19d1e43e43d, Jul  4 2024, 06:49:28) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.


>>> 
>>> s
>>> sor
>>> sorted(
>>> sorted(d
>>> sorted(di

>>> sorted(dir())



['__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__ior__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__ror__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']


>>> ex
>>> exit



CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

Linux, macOS

Linked PRs

@smontanaro smontanaro added the type-bug An unexpected behavior, bug, or error label Jul 4, 2024
@vstinner vstinner added the topic-repl Related to the interactive shell label Jul 4, 2024
@smontanaro
Copy link
Contributor Author

smontanaro commented Jul 4, 2024

I should point out that I have long had my own dir() function:

% ./python.exe -S -E 
Python 3.14.0a0 (heads/main:19d1e43e43d, Jul  4 2024, 06:49:28) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
>>> sorted(dir())
['__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
>>> type(dir)
<class 'builtin_function_or_method'>
>>> 

Contrast that with mine:

% ./python.exe       
Python 3.14.0a0 (heads/main:19d1e43e43d, Jul  4 2024, 06:49:28) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> type(dir)
<class 'function'>
>>> 

Shouldn't test_pyrepl be running the interpreter with something like -S -E?

Edit: Sorry, forgot to include the output of sorted(dir()) above:

>>> sorted(dir())
['__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__ior__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__ror__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
@vstinner
Copy link
Member

vstinner commented Jul 4, 2024

I should point out that I have long had my own dir() function

How is it installed?

@smontanaro
Copy link
Contributor Author

smontanaro commented Jul 4, 2024 via email

@smontanaro
Copy link
Contributor Author

Unsetting PYTHONSTARTUP worked:

(python312) ~/src/python/cpython% env | grep PYTHON
PYTHONSTARTUP=/Users/skip/.python.py
CONDA_PYTHON_EXE=/Users/skip/miniconda3/bin/python
(python312) ~/src/python/cpython% PYTHONSTARTUP= ./python.exe -E  -m test --fast-ci --timeout= -v test_pyrepl
+ ./python.exe -u -W default -bb -E -m test --fast-ci --timeout= -v test_pyrepl --dont-add-python-opts
== CPython 3.14.0a0 (heads/main:d4faa7bd321, Jul 5 2024, 11:13:24) [Clang 15.0.0 (clang-1500.3.9.4)]
== macOS-14.5-arm64-arm-64bit-Mach-O little-endian
== Python build: release
== cwd: /Users/skip/src/python/cpython/build/test_python_worker_63965æ
== CPU count: 8
== encodings: locale=UTF-8 FS=utf-8
== resources: all,-cpu

Using random seed: 725582968
0:00:00 load avg: 1.41 Run 1 test in parallel using 1 worker process (timeout: 10 min, worker timeout: 15 min)
0:00:03 load avg: 1.62 [1/1] test_pyrepl passed

== Tests result: SUCCESS ==

10 slowest tests:
- test_pyrepl: 3.7 sec

1 test OK.

Total duration: 3.7 sec
Total tests: run=118 skipped=1
Total test files: run=1/1
Result: SUCCESS
@vstinner
Copy link
Member

vstinner commented Jul 5, 2024

Shouldn't test_pyrepl be running the interpreter with something like -S -E?

I wrote PR #121414 to pass -I option to Python. Can you test the PR with your startup file?

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 5, 2024
run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
(cherry picked from commit 6239d41)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit to vstinner/cpython that referenced this issue Jul 5, 2024
run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
vstinner added a commit that referenced this issue Jul 5, 2024
run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
vstinner added a commit that referenced this issue Jul 5, 2024
gh-121359: Run test_pyrepl in isolated mode (GH-121414)

run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
(cherry picked from commit 6239d41)

Co-authored-by: Victor Stinner <vstinner@python.org>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
run_repl() now pass the -I option (isolated mode) to Python if the
'env' parameter is not set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
2 participants