changeset 52349:662b08ac9869

tests: enforce the use of `from __future__ import annotations` A recent MR and a separate recently landed MR that extracted code to a new file overlooked this, so I think it's worth flagging to ensure consistency. We don't enforce the import for empty files (like `__init__.py`). I'd rather this go into `import-checker.py`, but the import of interest only happens at the top of the file, and its `verify_modern_convention()` calls itself recursively as it transits the AST where the annotations might be. After a few hours of hacking on trying to get it to enforce the import, but only if annotations are used in the module (we generally don't have or check annotations in test files, so don't need this import), I gave up and resorted to this. It won't handle multi-line imports, but this isn't something I'd expect to change often, so this is good enough for now.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 29 Nov 2024 19:11:30 -0500
parents 99615755fb8e
children d4e30c15626d
files tests/test-check-module-imports.t
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-check-module-imports.t	Fri Nov 29 20:03:22 2024 -0500
+++ b/tests/test-check-module-imports.t	Fri Nov 29 19:11:30 2024 -0500
@@ -43,3 +43,10 @@
   > -X tests/test-verify-repo-operations.py \
   > -X tests/test-extension.t \
   > | sed 's-\\-/-g' | "$PYTHON" "$import_checker" -
+
+All files that get type checked must have 'from __future__ import annotations'
+
+  $ testrepohg files 'set:**.py and size(">0")' -I mercurial -I hgext -X mercurial/thirdparty -0 \
+  > | xargs -0 grep -L '^from __future__ import annotations$'
+  mercurial/cmd_impls/graft.py
+  mercurial/testing/ps_util.py