r-richmond opened a new issue #14396:
URL: https://github.com/apache/airflow/issues/14396


   **Description**
   
   Currently context is a dictionary. The dictionary is a bit nebulous 
especially for new users as it isn't clear what is present inside it and the 
autocomplete functionality of arbitrary dictionaries leaves a lot to be desired.
   
   Discoverability and type safety could be greatly improved if context was 
refactored into a dataclass (preferred) or typedDict(less ideal but probably 
easier).
   
   **Use case / motivation**
   
   Avoid having to know the keys present in context
   
   ```python
   def get_current_context() -> Dict:
     pass
     
   
   context = get_current_context()
       ti = context["ti"]
   ```
   would be instead
   ```python
   
   @dataclass
   class Context:
     # would be the place to see what values are in context and optionally 
include comments
     ti: TaskInstance # this is the task Instance
     ds: DateTime # This is the execution date
     # etc...
   
   def get_current_context() -> Context:
     pass
     
   context = get_current_context()
       #`context.` would have strong autocomplete here
       ti = context.ti
   
   
   ```
   
   **Are you willing to submit a PR?**
   
   This one touches too much of airflow's internals for me to try and tackle.
   
   **Related Issues**
   
   Not to my knowledge
   


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