grihabor commented on code in PR #41086:
URL: https://github.com/apache/airflow/pull/41086#discussion_r1696605455


##########
airflow/models/baseoperator.py:
##########
@@ -517,7 +517,11 @@ def __new__(cls, name, bases, namespace, **kwargs):
             partial_desc = vars(new_cls)["partial"]
             if isinstance(partial_desc, _PartialDescriptor):
                 partial_desc.class_method = classmethod(partial)
-        new_cls.__init__ = cls._apply_defaults(new_cls.__init__)
+
+        # We patch `__init__` only if the class defines it.
+        if inspect.getmro(new_cls)[1].__init__ is not new_cls.__init__:

Review Comment:
   The metaclass is set for the base class `BaseOperator`, so the `__init__` 
will be patched in every subclass. Here is a short example:
   ```python
   class InitMeta(type):
       def __new__(cls, name, bases, namespace, **kwargs):
           new_cls = super().__new__(cls, name, bases, namespace, **kwargs)
           print(f"setting {new_cls=}.__init__")
           new_cls.__init__ = new_cls.__init__
           return new_cls
   
   
   class A(metaclass=InitMeta):
       def __init__(self):
           print("A")
           super().__init__()
   
   
   class B(A):
       pass
   
   
   class C(A):
       def __init__(self):
           print("C")
           super().__init__()
   
   
   class D(B, C):
       pass
   
   
   D()
   ```
   And the output is
   ```
   setting new_cls=<class '__main__.A'>.__init__
   setting new_cls=<class '__main__.B'>.__init__
   setting new_cls=<class '__main__.C'>.__init__
   setting new_cls=<class '__main__.D'>.__init__
   A
   ``` 



-- 
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: [email protected]

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

Reply via email to