potiuk edited a comment on issue #14396:
URL: https://github.com/apache/airflow/issues/14396#issuecomment-785350406


   > While switching to dataclasses would be harder than TypedDicts it does not 
have to be a breaking change. You can convert dictionaries to dataclasses and 
vice versa pretty seamlessly. Although, implementing Dataclasses would 
certainly be more work to get right in the initial pr.
   
   Let me explain why this would be a breaking change.  if you have an operator 
that already uses context. Example from task decorator case (but this is the 
same for any custom operator):
   
   ```
   from airflow.operators.python import task, get_current_context
   
   @task
   def my_task():
       context = get_current_context()
       ti = context["ti"]
   ```
   
   Surely you can map from Dataclass to Dict in "get_current_context()" method 
(otherwise you'd have to also correct the `context["ti"]` into `context.ti`. 
Thus it would be a breaking change.
   
   But if you do that (i.e map dataclass to dict), then you loose the type 
hinting. This is precisely the place where typehinting is needed (in the user 
code). And I think Typed Dict (if used everywhere including return value from 
get_current_context() gives you what you need from the  user point of view and 
there is no need to implement the `> Dataclass` step - as you have everything 
you need by implementing TypeDict. 
   
   Or maybe I am  missing something?
   
   > Personally I'm of the opinion that working with the dataclass api is 
superior to working with the dictionary api due to the reasons outlined above 
but thats just like my opinion man.
   
   In a number of cases yes. But in others flexibility of the dict and fact 
that you can add any value there, trumps.
   


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