Skip to content

[clang-tidy] remove type annotations that require python3.9 in add_new_check.py #107850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

5chmidti
Copy link
Contributor

@5chmidti 5chmidti commented Sep 9, 2024

Subscripting re.Match: re.Match[str] is not supported until python 3.9.
Tested with python 3.8.19, 3.9.19 and 3.12.4.

Fixes #107846

…w_check.py

Subscripting `Tuple`: `Tuple[str, str]` is not supported until python 3.9.
Tested with python 3.8.19, 3.9.19 and 3.12.4.

Fixes llvm#107846
@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Julian Schmidt (5chmidti)

Changes

Subscripting Tuple: Tuple[str, str] is not supported until python 3.9.
Tested with python 3.8.19, 3.9.19 and 3.12.4.

Fixes #107846


Full diff: https://github.com/llvm/llvm-project/pull/107850.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/add_new_check.py (+3-3)
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index d384dbae28abbc..7230b3b17b2b79 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -511,7 +511,7 @@ def has_auto_fix(check_name: str) -> str:
 
         return ""
 
-    def process_doc(doc_file: Tuple[str, str]) -> Tuple[str, Optional[re.Match[str]]]:
+    def process_doc(doc_file):
         check_name = doc_file[0] + "-" + doc_file[1].replace(".rst", "")
 
         with io.open(os.path.join(docs_dir, *doc_file), "r", encoding="utf8") as doc:
@@ -526,7 +526,7 @@ def process_doc(doc_file: Tuple[str, str]) -> Tuple[str, Optional[re.Match[str]]
             # Is it a redirect?
             return check_name, match
 
-    def format_link(doc_file: Tuple[str, str]) -> str:
+    def format_link(doc_file) -> str:
         check_name, match = process_doc(doc_file)
         if not match and check_name and not check_name.startswith("clang-analyzer-"):
             return "   :doc:`%(check_name)s <%(module)s/%(check)s>`,%(autofix)s\n" % {
@@ -538,7 +538,7 @@ def format_link(doc_file: Tuple[str, str]) -> str:
         else:
             return ""
 
-    def format_link_alias(doc_file: Tuple[str, str]) -> str:
+    def format_link_alias(doc_file) -> str:
         check_name, match = process_doc(doc_file)
         if (match or (check_name.startswith("clang-analyzer-"))) and check_name:
             module = doc_file[0]

Copy link
Contributor

@nicovank nicovank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented in issue but I think the problem is with re.Match not Tuple. Python docs seem to show Tuple had subscripting from its introduction in 3.5.

The script currently passes a strict mypy check which requires all parameters annotated, would be nice to keep it.

python3 -m mypy --strict ./clang-tools-extra/clang-tidy/add_new_check.py

Copy link
Contributor

@nicovank nicovank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@HerrCai0907
Copy link
Contributor

I think the reason is python3.8 don't support re.Match. see #107871

@5chmidti 5chmidti closed this Sep 12, 2024
@5chmidti 5chmidti deleted the clang_tidy_fix_add_new_check_wrt_python_38 branch September 12, 2024 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-tidy] add_new_check.py fails with "TypeError: 'type' object is not subscriptable"
4 participants