You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2023/08/23 00:59:02 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #33592: Use str.splitlines() to split lines

uranusjr commented on code in PR #33592:
URL: https://github.com/apache/airflow/pull/33592#discussion_r1302335832


##########
airflow/utils/file.py:
##########
@@ -215,21 +215,21 @@ def _find_path_from_directory(
 
         ignore_file_path = Path(root) / ignore_file_name
         if ignore_file_path.is_file():
-            with open(ignore_file_path) as ifile:
-                lines_no_comments = [re2.sub(r"\s*#.*", "", line) for line in ifile.read().split("\n")]
-                # append new patterns and filter out "None" objects, which are invalid patterns
-                patterns += [
-                    p
-                    for p in [
-                        ignore_rule_type.compile(line, Path(base_dir_path), ignore_file_path)
-                        for line in lines_no_comments
-                        if line
-                    ]
-                    if p is not None
+            lines = ignore_file_path.read_text().splitlines()

Review Comment:
   I would keep the `with open` style and rewrite the reading part to
   
   ```python
   [re2.sub(r"\s*#.*", "", line) for line in ifile]
   ```
   
   This would allow the input to be read line by line instead of creating a temporary string before splitting.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org