uranusjr commented on code in PR #37894:
URL: https://github.com/apache/airflow/pull/37894#discussion_r1512402026
##########
airflow/utils/file.py:
##########
@@ -377,6 +377,10 @@ def iter_airflow_imports(file_path: str) -> Generator[str,
None, None]:
"""Find Airflow modules imported in the given file."""
try:
parsed = ast.parse(Path(file_path).read_bytes())
+ except ValueError as e:
+ if "source code string cannot contain null bytes" in str(e):
+ log.warning(f"The file {file_path} contains null bytes and cannot
be parsed.")
Review Comment:
Instead of trying to parse the exception, it would be easier to do
```python
try:
data = Path(file_path).read_bytes()
if 0 in data:
log.warning(...)
parsed = ast.parse(data)
except Exception:
return
```
Also, [do not use an f-string with
logging](https://docs.astral.sh/ruff/rules/logging-f-string/).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]