-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[clang-tidy] remove type annotations that require python3.9 in add_new_check.py #107850
Conversation
…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
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Julian Schmidt (5chmidti) ChangesSubscripting Fixes #107846 Full diff: https://github.com/llvm/llvm-project/pull/107850.diff 1 Files Affected:
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]
|
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I think the reason is python3.8 don't support re.Match. see #107871 |
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