You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "/home/mark/repos/cpython/Lib/inspect.py", line 1154, in walktree
classes.sort(key=attrgetter('__module__', '__name__'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'module'
I can reproduce that failure with a debug build and either of
./python -m test -R 3:3 test_inspect
./python -m test test_inspect -F
f468ede is the first bad commit
commit f468ede
Author: Miss Islington (bot) <[email protected]>
Date: Fri Jul 30 10:46:42 2021 -0700
bpo-44648: Fix error type in inspect.getsource() in interactive session (GH-27171) (GH-27495)
(cherry picked from commit 48a62559dfaf775e4f1cc56b19379c799e8e2587)
Co-authored-by: andrei kulakov <[email protected]>
PR 27544 just addresses the main problem, but I still have concerns about the test affecting sys.modules directly, making it dangerous to run in parallel.
Pablo: thanks for investigating and fixing this, I will look for examples of changing or patching sys.modules in the testsuite to see how to avoid global effects. I think we can keep this issue open for the follow-up discussion / fix?
I've been looking into avoiding global modification of modules['__main__'], the options are:
remove the test and leave it at that
remove the test and open a new issue for re-adding a test ; and look for a way to do it safely
create a temp script file, add code to it that creates a class, sets sys.modules['__main__'].__file__ = None and inspects the class, and run this module in a new interpreter, checks exception raised and does sys.exit(1); and check the exit code after running this script.
patch inspect.sys.modules; as far as I understand, this would mean other modules accessing sys.modules in other threads won't be affected, and sys.modules['__main__'] is currently used in inspect in a very limited way, so it can probably be shown that this patching won't affect other tests that use inspect, -- but I would need to look more into this.
I'm not sure if #3 is too heavy/complex for this test.
The advantage of #1 and #2 is that it's easy to do and ensures that there won't be strange random test failures that are hard to track down and debug (which is something that I'm afraid can happen right now, caused by this test).
Activity
pablogsal commentedon Aug 2, 2021
From https://bugs.python.org/issue44206 :
File "/home/mark/repos/cpython/Lib/inspect.py", line 1154, in walktree
classes.sort(key=attrgetter('__module__', '__name__'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'module'
I can reproduce that failure with a debug build and either of
./python -m test -R 3:3 test_inspect
./python -m test test_inspect -F
pablogsal commentedon Aug 2, 2021
I'm bisecting
pablogsal commentedon Aug 2, 2021
f468ede is the first bad commit
commit f468ede
Author: Miss Islington (bot) <[email protected]>
Date: Fri Jul 30 10:46:42 2021 -0700
Lib/inspect.py | 2 ++
Lib/test/test_inspect.py | 17 ++++++++++++++++-
.../Library/2021-07-15-16-51-32.bpo-44648.2o49TB.rst | 3 +++
3 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 Misc/NEWS.d/next/Library/2021-07-15-16-51-32.bpo-44648.2o49TB.rst
pablogsal commentedon Aug 2, 2021
The reason buildbots have not catched this is because the re-run login seems to not detect the problem on the second run:
./python.exe -m test test_inspect -j 1 -u all -W --slowest --fail-env-changed --timeout=11700 -R 3:3 -u-cpu -w
== Tests result: FAILURE ==
10 slowest tests:
1 test failed:
test_inspect
1 re-run test:
test_inspect
0:00:03 load avg: 2.92 Re-running failed tests in verbose mode
0:00:03 load avg: 2.92 Re-running test_inspect in verbose mode (matching: test_getclasses)
beginning 6 repetitions
123456
test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.test_getclasses (test.test_inspect.TestRetrievingSourceCode) ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
.
== Tests result: FAILURE then SUCCESS ==
1 test OK.
10 slowest tests:
Total duration: 4.6 sec
Tests result: FAILURE then SUCCESS
pablogsal commentedon Aug 2, 2021
Check for instance the logs in https://buildbot.python.org/all/#/builders/679/builds/92/steps/5/logs/stdio
pablogsal commentedon Aug 2, 2021
From f468ede:
This code looks quite dangerous:
That is modifing sys.modules globally!
pablogsal commentedon Aug 2, 2021
Ah, the problem is that:
is wrong:
__module__must be a string, not a module objectpablogsal commentedon Aug 2, 2021
PR 27544 just addresses the main problem, but I still have concerns about the test affecting sys.modules directly, making it dangerous to run in parallel.
pablogsal commentedon Aug 2, 2021
With PR 27544:
❯ ./python.exe -m test test_inspect -R :
0:00:00 load avg: 2.91 Run tests sequentially
0:00:00 load avg: 2.91 [1/1] test_inspect
beginning 9 repetitions
123456789
.........
== Tests result: SUCCESS ==
1 test OK.
Total duration: 13.7 sec
Tests result: SUCCESS
ambv commentedon Aug 2, 2021
New changeset 626d397 by Pablo Galindo Salgado in branch 'main':
bpo-44808: Fix test_inspect in refleak mode (GH-27544)
626d397
akulakov commentedon Aug 2, 2021
Pablo: thanks for investigating and fixing this, I will look for examples of changing or patching sys.modules in the testsuite to see how to avoid global effects. I think we can keep this issue open for the follow-up discussion / fix?
miss-islington commentedon Aug 2, 2021
New changeset a1eaa74 by Miss Islington (bot) in branch '3.10':
bpo-44808: Fix test_inspect in refleak mode (GH-27544)
a1eaa74
akulakov commentedon Aug 2, 2021
I've been looking into avoiding global modification of modules['__main__'], the options are:
remove the test and leave it at that
remove the test and open a new issue for re-adding a test ; and look for a way to do it safely
create a temp script file, add code to it that creates a class, sets
sys.modules['__main__'].__file__ = Noneand inspects the class, and run this module in a new interpreter, checks exception raised and does sys.exit(1); and check the exit code after running this script.patch inspect.sys.modules; as far as I understand, this would mean other modules accessing sys.modules in other threads won't be affected, and sys.modules['__main__'] is currently used in inspect in a very limited way, so it can probably be shown that this patching won't affect other tests that use inspect, -- but I would need to look more into this.
I'm not sure if #3 is too heavy/complex for this test.
The advantage of #1 and #2 is that it's easy to do and ensures that there won't be strange random test failures that are hard to track down and debug (which is something that I'm afraid can happen right now, caused by this test).
#4 I've added to get comments / thought.
akulakov commentedon Aug 3, 2021
Please disregard my last comment, I think I found a good way to fix it, the PR is up here:
https://github.com/python/cpython/pull/27571/files
ambv commentedon Aug 3, 2021
New changeset 5832597 by andrei kulakov in branch 'main':
bpo-44808: fixes test for interactive inspect getsource of a class (GH-27571)
5832597
miss-islington commentedon Aug 3, 2021
New changeset bc2841c by Miss Islington (bot) in branch '3.10':
bpo-44808: fixes test for interactive inspect getsource of a class (GH-27571)
bc2841c