-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[analyzer][NFC] Simplify Analysis/csv2json.py #161665
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
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) ChangesFull diff: https://github.com/llvm/llvm-project/pull/161665.diff 1 Files Affected:
diff --git a/clang/test/Analysis/csv2json.py b/clang/test/Analysis/csv2json.py
index 3c20d689243e7..d7fb3491f82fa 100644
--- a/clang/test/Analysis/csv2json.py
+++ b/clang/test/Analysis/csv2json.py
@@ -44,7 +44,7 @@ def csv_to_json_dict(csv_filepath):
"""
try:
with open(csv_filepath, "r", encoding="utf-8") as csvfile:
- reader = csv.reader(csvfile)
+ reader = csv.reader(csvfile, skipinitialspace=True)
# Read the header row (column names)
try:
@@ -58,19 +58,19 @@ def csv_to_json_dict(csv_filepath):
json.dumps({}, indent=2)
return
- other_column_names = [name.strip() for name in header[1:]]
+ header_length = len(header)
data_dict = {}
for row in reader:
- if len(row) != len(header):
+ if len(row) != header_length:
raise csv.Error("Inconsistent CSV file")
exit(1)
key = row[0]
value_map = {}
- for i, col_name in enumerate(other_column_names):
+ for i, col_name in enumerate(header[1:]):
# +1 to skip the first column
value_map[col_name] = row[i + 1].strip()
|
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.
LGTM, seems to be a nice simplification.
Note that skipinitialspace
is not completely identical to the .strip()
call because it only strips the whitespace before the actual value, while .strip()
would also strip whitespace after the value (and before the separator mark). If this script needs to handle input like foo , bar , baz , spam
(with spaces before the separator ,
), then you should keep the original code. (However, I presume that your usecase is handling input like foo, bar, baz, spam
.)
No description provided.