Skip to content

Use an argument list in test_typing_extensions_compiles_with_opt - #786

Open
rhettcarillo wants to merge 1 commit into
python:mainfrom
rhettcarillo:argv-in-opt-compile-test
Open

Use an argument list in test_typing_extensions_compiles_with_opt#786
rhettcarillo wants to merge 1 commit into
python:mainfrom
rhettcarillo:argv-in-opt-compile-test

Conversation

@rhettcarillo

Copy link
Copy Markdown

test_typing_extensions_compiles_with_opt builds a shell command string from
sys.executable and typing_extensions.__file__ without quoting either:

subprocess.check_output(f'{sys.executable} -OO {file_path}',
                        stderr=subprocess.STDOUT,
                        shell=True)

When the checkout (or the interpreter) is under a path containing a space, the shell
splits the path and the subprocess fails for that reason alone. Because the except
clause maps any CalledProcessError to 'Module does not compile with optimize=2 (-OO flag).', the failure is indistinguishable from a real -OO compilation error —
which is the part that cost me some time before I looked at the command being run.

Replacing the string with an argument list needs no quoting and no shell.

Reproducing

On any checkout whose path contains a space (mine is on Windows, but the same applies
to /home/user/my projects/...):

$ cd src/
$ python -m unittest test_typing_extensions.AllTests.test_typing_extensions_compiles_with_opt
AssertionError: Module does not compile with optimize=2 (-OO flag).

typing_extensions compiles fine under -OO; only the test is broken.

With this change, from the same directory:

$ python -m unittest test_typing_extensions.AllTests.test_typing_extensions_compiles_with_opt
Ran 1 test in 0.265s
OK

Full suite on the same checkout: Ran 576 tests ... OK (skipped=24).

Notes

  • Test-only change; no behavior change in typing_extensions itself, so I have not
    added a CHANGELOG entry — happy to add one if you would prefer.
  • Disclosure: this was found and prepared with AI assistance (Claude), which is why the
    commit carries a Co-Authored-By trailer. The reproduction, the fix and the test runs
    above are real and were executed on my machine; I am happy to adjust or drop the
    trailer if it conflicts with your policy.

The test built a shell command string from sys.executable and
typing_extensions.__file__ without quoting either. When the checkout or
the interpreter lives under a path containing a space, the shell splits
the path and the subprocess fails for that reason alone -- and because
the except clause maps any CalledProcessError to "Module does not
compile with optimize=2", the failure is indistinguishable from a real
-OO compilation error.

An argument list needs no quoting and no shell, so the test measures
what it means to measure on every path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@python-cla-bot

python-cla-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (79c903c) to head (77c2457).

@@           Coverage Diff           @@
##             main     #786   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files           3        3           
  Lines        7859     7859           
=======================================
  Hits         7644     7644           
  Misses        215      215           
Flag Coverage Δ
3.10 88.85% <100.00%> (ø)
3.10.4 88.85% <100.00%> (ø)
3.11 88.02% <100.00%> (ø)
3.11.0 87.27% <100.00%> (ø)
3.12 87.96% <100.00%> (ø)
3.12.0 87.94% <100.00%> (ø)
3.13 83.39% <100.00%> (ø)
3.13.0 84.09% <100.00%> (ø)
3.14 79.53% <100.00%> (ø)
3.9 89.53% <100.00%> (ø)
3.9.12 89.53% <100.00%> (ø)
pypy3.10 88.68% <100.00%> (ø)
pypy3.11 87.88% <100.00%> (ø)
pypy3.9 89.37% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/test_typing_extensions.py 98.23% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rhettcarillo

Copy link
Copy Markdown
Author

Closing and reopening to re-trigger the CLA check — the agreement has now been signed. Apologies for the notification noise.

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.

2 participants