-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Closed
Labels
Description
Hello,
Currently, the signatures of most operators look similar to the following.
@apply_defaults
def __init__(
self, sql: str, conn_id: Optional[str] = None, *args, **kwargs
) -> None:
super().__init__(*args, **kwargs)
self.conn_id = conn_id
self.sql = sqlThere are two problems here.
- The
apply_defaultdecorator forces all arguments to be passed as keyword arguments, but this information is not marked in the signature. As of Python 3 it is possible to mark arguments as keyword-only argument. - The
*argsis passed to the BaseOperator class, but this class does not accept positional arguments.
The new operator signature may look like folllow
@apply_defaults
def __init__(
self, *, sql: str, conn_id: Optional[str] = None, **kwargs
) -> None:
super().__init__(**kwargs)
self.conn_id = conn_id
self.sql = sqlThis change will allow the detection of improper operator initialization by static code analysis tools. This will also improve the operator's documentation as the method signature is available in the Python API Reference.
This change is backward-compatible because the positional arguments were not accepted before, but this was not enforced by the Python interpreter, but by an ddecorator.
We can use Bowler to do it.
Best regards,
Kamil
potiuk, ad-m, turbaszek and bhavaniravi