Skip to content

Conversation

steakhal
Copy link
Contributor

@steakhal steakhal commented Oct 2, 2025

No description provided.

@steakhal steakhal requested review from NagyDonat and necto October 2, 2025 13:28
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)

Changes

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

1 Files Affected:

  • (modified) clang/test/Analysis/csv2json.py (+4-4)
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()
 

Copy link
Contributor

@NagyDonat NagyDonat left a 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.)

@steakhal steakhal merged commit 13c83c0 into llvm:main Oct 3, 2025
9 checks passed
@steakhal steakhal deleted the simplify-csv2json branch October 3, 2025 13:14
MixedMatched pushed a commit to MixedMatched/llvm-project that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants