[llvm] code-format: Improve the code-format-helper to be able to run as a git hook (PR #73957)

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 06:30:24 PST 2023


================
@@ -31,9 +45,10 @@ def comment_tag(self) -> str:
     def instructions(self) -> str:
         raise NotImplementedError()
 
-    def format_run(
-        self, changed_files: list[str], args: argparse.Namespace
-    ) -> str | None:
+    def has_tool(self) -> bool:
+        raise NotImplementedError()
+
+    def format_run(self, changed_files: list[str], args: FormatArgs) -> str | None:
----------------
ldionne wrote:

What version of Python is required to run this hook? With `Python 3.9.6`, I'm getting this error:

```
  File "/Users/ldionne/code/llvm/.git/hooks/pre-commit", line 35, in <module>
    class FormatHelper:
  File "/Users/ldionne/code/llvm/.git/hooks/pre-commit", line 51, in FormatHelper
    def format_run(self, changed_files: list[str], args: FormatArgs) -> str | None:
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
```

I think this is because `str | None` is not recognized as a type annotation in that version of Python?

https://github.com/llvm/llvm-project/pull/73957


More information about the llvm-commits mailing list