-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
[AIRFLOW-5359] Update type annotations in BaseOperator #5965
[AIRFLOW-5359] Update type annotations in BaseOperator #5965
Conversation
CC: @ashb |
airflow/models/baseoperator.py
Outdated
execution_timeout: Optional[timedelta] = None, | ||
on_failure_callback: Optional[Callable] = None, | ||
on_success_callback: Optional[Callable] = None, | ||
on_retry_callback: Optional[Callable] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Optional[Callable]
, all the callbacks are optional so they can take None or a callable function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've raised question about Optional
type on Airflow Slack here.
It was pointed there that arguments with a None
default value are having an implicit Optional[...]
type. It is default mypy
behavior until it is not configured differently. Documentation about it here: The mypy command line - None and Optional handling and here: The mypy configuration file - None and Optional handling.
Due to this I assumed less code is better and I wanted to make annotations to be more consistent (some of them have Optional
and some not). I had the same approach in another PR [AIRFLOW-5360] Type annotations for BaseSensorOperator and some future ones on which I am currently working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a huge discussion here: python/typing#275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @potiuk for that link.
Following discussion in python/typing#275, there is a consensus that it is better to require optional types to be made explicit. This PR changes the wording of PEP 484 to allow, but not require, type checkers to treat a None default as implicitly making an argument Optional.
So please let's not change this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/peps#689 for you reference @TobKed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I read a bit more in detail and actually what I think now (I changed my mind) since there is this "trend" and possible future breaking change to disallow implicit Optional, maybe we should do more than that - namely we should convert all implicit Optionals and add '--disable-implicit-optional' flag to mypy and prevent anyone from ever adding implicit Optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
airflow/models/baseoperator.py
Outdated
do_xcom_push: bool = True, | ||
inlets: Optional[Dict] = None, | ||
outlets: Optional[Dict] = None, | ||
inlets: Dict = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation
Code Quality
flake8