Mercurial > public > mercurial-scm > hg-stable
changeset 52684:70a75d379daf
tests: obfuscate Python version checks to subvert `pyupgrade`
When specifying `--py38-plus`, it reasonably deletes conditionals that check for
that version of python or earlier. But we actually want the check to remain, so
use a simple obfuscation to preserve it.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Tue, 07 Jan 2025 17:52:52 -0500 |
parents | c975e8ec08bb |
children | 1c8bc6110a1a |
files | tests/fsmonitor-run-tests.py tests/run-tests.py |
diffstat | 2 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/fsmonitor-run-tests.py Tue Jan 07 17:46:56 2025 -0500 +++ b/tests/fsmonitor-run-tests.py Tue Jan 07 17:52:52 2025 -0500 @@ -24,7 +24,11 @@ osenvironb = getattr(os, 'environb', os.environ) -if sys.version_info >= (3, 8, 0): +# Don't compare sys.version_info directly, to prevent pyupgrade from dropping +# the conditional. +sys_version_info = sys.version_info + +if sys_version_info >= (3, 8, 0): def _sys2bytes(p): return p.encode('utf-8')
--- a/tests/run-tests.py Tue Jan 07 17:46:56 2025 -0500 +++ b/tests/run-tests.py Tue Jan 07 17:52:52 2025 -0500 @@ -73,7 +73,11 @@ import xml.dom.minidom as minidom -if sys.version_info < (3, 8, 0): +# Don't compare sys.version_info directly, to prevent pyupgrade from dropping +# the conditional. +sys_version_info = sys.version_info + +if sys_version_info < (3, 8, 0): print( '%s is only supported on Python 3.8+, not %s' % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3]))