Verify decorators parameter in __init__.pyi matches operator
related: #48448 closes: #48448
Add tests to all existed decorators to make sure the parameter list they accept matches the operator.
In this PR, I have added tests to verify the match using the libcst library. i have included tests for few decorators and once i get reviews if this way of verifying is fine, i will add the other decorator case too. cc: @eladkal
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.
I like the idea, but this feels like it belongs to a pre-commit check rather than a unit test.
I like the idea, but this feels like it belongs to a pre-commit check rather than a unit test.
yes that makes sense. let me add this as part of precommit test.
@uranusjr There are some complexities in moving to pre-commit. As unit tests, they run within the virtualenv and are context-aware, running without issue. But to run as part of a pre-commit hook, setting up the path has to be done. even when done,
module = __import__(module_path, fromlist=[class_name])
This part of the code in the test loads and runs the module in real-time, triggering a missing dependency issue at runtime. how do you think this could be better handled?
@uranusjr when you have time, could you help me handle the above issue?
@amoghrajesh @potiuk @uranusjr If any of you get time, could you help me in understanding if this can be better handled?
@Bowrna I also think its not a great idea to add this in unit tests but in precommit checks to catch things earlier and repeatedly.
Did you try using the inspect library and matching signatures.
Python 3.9.22 (main, Apr 30 2025, 00:01:18)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import sys
>>> import inspect
>>> from airflow.decorators import task
>>> from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
>>> op_sig = inspect.signature(KubernetesPodOperator.__init__)
>>> dec_sig = inspect.signature(task.kubernetes)
>>> op_params = {k for k in op_sig.parameters}
>>> dec_params = {k for k in dec_sig.parameters}
>>>
>>>
>>> diff_op = op_params - dec_params
>>> diff_dec = dec_params - op_params
>>>
>>>
>>> diff_op
{'volume_mounts', 'env_from', 'base_container_status_polling_interval', 'kubernetes_conn_id', 'ports', 'on_finish_action', 'do_xcom_push', 'cmds', 'arguments', 'image', 'random_name_suffix', 'name', 'dnspolicy', 'config_file', 'cluster_context', 'full_pod_spec', 'dns_config', 'labels', 'self', 'termination_message_policy', 'volumes', 'skip_on_exit_code', 'is_delete_operator_pod', 'init_container_logs', 'active_deadline_seconds', 'container_resources', 'logging_interval', 'container_security_context', 'affinity', 'startup_timeout_seconds', 'termination_grace_period', 'hostnetwork', 'callbacks', 'startup_check_interval_seconds', 'init_containers', 'image_pull_secrets', 'host_aliases', 'deferrable', 'base_container_name', 'log_pod_spec_on_failure', 'poll_interval', 'get_logs', 'pod_template_dict', 'security_context', 'in_cluster', 'configmaps', 'subdomain', 'pod_runtime_info_envs', 'service_account_name', 'hostname', 'secrets', 'container_logs', 'trigger_kwargs', 'schedule_timeout_seconds', 'log_events_on_failure', 'reattach_on_restart', 'image_pull_policy', 'tolerations', 'progress_callback', 'namespace', 'automount_service_account_token', 'node_selector', 'priority_class_name', 'env_vars', 'pod_template_file', 'schedulername', 'annotations'}
>>> diff_dec
{'multiple_outputs', 'python_callable'}
Tried with the console and it works pretty consistently.
@uranusjr could you review this PR and share your feedback?
@uranusjr the fix you suggested is added into this. thank you. when you get, please verify this PR and share your feedback.
@uranusjr do i have any update regarding this PR?
@potiuk @uranusjr I am facing a weird issue where my static checks pass in the local instance and once committed it starts to fail. could you help me in identifying issue ?
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.