You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/17 03:54:45 UTC

[GitHub] [airflow] uranusjr commented on issue #27081: Wrong missing args error when initialising operator with multiple inheritance

uranusjr commented on issue #27081:
URL: https://github.com/apache/airflow/issues/27081#issuecomment-1280243692

   > work as expected in Python.
   
   How? I removed `BaseOperator` from the given example:
   
   ```python
   class R:
       def __init__(**kwargs):
           pass
   
   class A(R):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class B(R):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(**kwargs)
   
   class C(A, B):
       def __init__(self, *, value: str, **kwargs):
           super().__init__(value=value, **kwargs)
   
   C(task_id="test", value="value")
   ```
   
   And it still fails.
   
   ```
   Traceback (most recent call last):
     File "<stdin>", line 24, in <module>
       C(task_id="test", value="value")
     File "<stdin>", line 21, in __init__
       super().__init__(value=value, **kwargs)
     File "<stdin>", line 11, in __init__
       super().__init__(**kwargs)
   TypeError: __init__() missing 1 required keyword-only argument: 'value'
   ```
   
   Python’s `super` chain follows MRO (C→B→A→BaseOperator in this example), so the `super().__init__` calls in `C.__init__` calls `B.__init__`, **and the `super().__init__` in `B.__init__` calls `A.__init__`**, which is missing the required `value` argument.
   
   From what I can tell, `apply_defaults` is doing its job properly. It obscures the traceback, which we could improve, but the error is legistimate.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org