Skip to content
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

add detection of attribute callables in XComChecker #24

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add filtering for builtins/attributes in get_xcoms_from_tasks
  • Loading branch information
topherinternational committed Jan 5, 2024
commit 8e07c13b7881ccfbc8dba382b4f6e0552b2d70b6
9 changes: 7 additions & 2 deletions src/pylint_airflow/checkers/xcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Set, Dict, Tuple

import astroid
from astroid import AttributeInferenceError
from pylint import checkers
from pylint.checkers import utils

Expand Down Expand Up @@ -83,8 +84,12 @@ def get_xcoms_from_tasks(
if callable_func_name == "<lambda>": # TODO support lambdas
continue

callable_func = node.getattr(callable_func_name)[0]
# ^ TODO: handle builtins and attribute imports that will raise on this call
try:
module_attribute = node.getattr(callable_func_name)
except AttributeInferenceError:
continue
else:
callable_func = module_attribute[0]

if not isinstance(callable_func, astroid.FunctionDef):
continue # Callable_func is str not FunctionDef when imported
Expand Down
9 changes: 0 additions & 9 deletions tests/pylint_airflow/checkers/test_xcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ def test_should_skip_lambda_callable(self):

assert result == ({}, set())

@pytest.mark.xfail(
reason="Not yet implemented", raises=astroid.AttributeInferenceError, strict=True
)
def test_should_skip_builtin_callable(self):
test_code = """
from airflow.operators.python_operator import PythonOperator
Expand All @@ -206,9 +203,6 @@ def test_should_skip_builtin_callable(self):

assert result == ({}, set())

@pytest.mark.xfail(
reason="Not yet implemented", raises=astroid.AttributeInferenceError, strict=True
)
def test_should_skip_imported_callable_as_attribute(self):
test_code = """
from airflow.operators.python_operator import PythonOperator
Expand Down Expand Up @@ -243,9 +237,6 @@ def test_should_skip_imported_callable_as_name(self):

assert result == ({}, set())

@pytest.mark.xfail(
reason="Not yet implemented", raises=astroid.AttributeInferenceError, strict=True
)
def test_should_skip_local_function_callables_as_attributes(self):
test_code = """
from airflow.operators.python_operator import PythonOperator
Expand Down