Skip to content

Commit

Permalink
Fix EnforceTaskFlowApi for task
Browse files Browse the repository at this point in the history
- do not replace if callable is a lambda
  • Loading branch information
feluelle committed Apr 21, 2022
1 parent 2a79534 commit f86e7b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions airflint/rules/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def match(self, node):
and isinstance(node.value.func, ast.Name)
and node.value.func.id in ["PythonOperator", "PythonVirtualenvOperator"]
and isinstance(node.value.func.ctx, ast.Load)
and any(
keyword.arg == "python_callable" and isinstance(keyword.value, ast.Name)
for keyword in node.value.keywords
)
)

args = next(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ def foo():
task = PythonOperator(task_id="foo", python_callable=foo)
""",
),
(
task.EnforceTaskFlowApi,
"""
from airflow.operators.python import PythonOperator
PythonOperator(task_id="foo", python_callable=lambda: "foo")
""",
"""
from airflow.operators.python import PythonOperator
from airflow.decorators import task
PythonOperator(task_id="foo", python_callable=lambda: "foo")
""",
),
(
task.EnforceTaskFlowApi,
"""
Expand Down

0 comments on commit f86e7b2

Please sign in to comment.