Skip to content

[clang-tidy][NFC] fix add_new_check python3.8 incompatibility #107871

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

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

HerrCai0907
Copy link
Contributor

Fixes: #107846

@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)

Changes

Fixes: #107846


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/add_new_check.py (+2-2)
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index d384dbae28abbc..e366f100535357 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -17,7 +17,7 @@
 import textwrap
 
 # FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
-from typing import Optional, Tuple
+from typing import Optional, Tuple, Match
 
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
@@ -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: Tuple[str, str]) -> Tuple[str, Optional[Match[str]]]:
         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:

@llvmbot
Copy link
Member

llvmbot commented Sep 9, 2024

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

Author: Congcong Cai (HerrCai0907)

Changes

Fixes: #107846


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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/add_new_check.py (+2-2)
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index d384dbae28abbc..e366f100535357 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -17,7 +17,7 @@
 import textwrap
 
 # FIXME Python 3.9: Replace typing.Tuple with builtins.tuple.
-from typing import Optional, Tuple
+from typing import Optional, Tuple, Match
 
 
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new
@@ -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: Tuple[str, str]) -> Tuple[str, Optional[Match[str]]]:
         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:

@nicovank
Copy link
Contributor

nicovank commented Sep 9, 2024

I see typing.Match will be removed in 3.13. I'm not sure if that means it won't work altogether with 3.13 or just the typecheck.

image

My vote goes to Any and switch back to re.Match when LLVM minimum is bumped >= 3.9 (#107850).

@nicovank
Copy link
Contributor

nicovank commented Sep 9, 2024

Update: I misread the docs, typing.re is what's going to be removed, typing.Match is only deprecated but not planned for removal yet. Still think Any is the way to go to avoid introducing the deprecated type but either solution is actually fine.

@HerrCai0907
Copy link
Contributor Author

actually both are fine. since 3.8 will stop maintain soon. It just a temp solution and may be alive only in half year.

@nicovank
Copy link
Contributor

nicovank commented Sep 9, 2024

Exactly, IMO the move to 3.9 minimum should be in 6-12 months to leave a bit of time after EOL. 3.9 also has subscriptable tuple, list and dict which is nice.

@HerrCai0907 HerrCai0907 merged commit 39751e7 into llvm:main Sep 12, 2024
11 checks passed
@HerrCai0907 HerrCai0907 deleted the fix/add-new-check branch September 12, 2024 01:51
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