mik-laj opened a new issue #9942:
URL: https://github.com/apache/airflow/issues/9942


   Hello,
   
   Currently, the signatures of most operators look similar to the following.
   ```python
       @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 = sql
   ```
   There are two problems here.
   1. The ``apply_default`` decorator 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](https://www.python.org/dev/peps/pep-3102/).
   2. The `*args` is passed to the BaseOperator class, but this class does not 
accept positional arguments.
   
   The new operator signature may look like folllow
   ```python
       @apply_defaults
       def __init__(
           self, *, sql: str, conn_id: Optional[str] = None, **kwargs
       ) -> None:
           super().__init__(**kwargs)
           self.conn_id = conn_id
           self.sql = sql
   ```
   
   This change will allow the detection of improper operator initialization by 
static code analysis tools.
   
   Best regards,
   Kamil
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to