# HG changeset patch # User Matt Harbison # Date 2024-11-30 00:11:30 # Node ID 662b08ac9869b93a95657e753542373a81c1ec25 # Parent 99615755fb8e6ae68ac3d13d3a536b3ae39e299a 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. diff --git a/tests/test-check-module-imports.t b/tests/test-check-module-imports.t --- a/tests/test-check-module-imports.t +++ b/tests/test-check-module-imports.t @@ -43,3 +43,10 @@ will likely receive warnings about a dir > -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