You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "maxestorr (via GitHub)" <gi...@apache.org> on 2024/12/02 13:11:40 UTC

Re: [I] Type hinted `@task` decorated functions to create typed XComs [airflow]

maxestorr commented on issue #19884:
URL: https://github.com/apache/airflow/issues/19884#issuecomment-2511505885

   > This may be possible in the future, but I wouldn’t recommend doing this right now. Python core devs’ official stance on type hints, at least at the current time, is that they are merely hints and should not be relied on by runtime logic. The last people that do this kind of thing extensively—Pydantic and FastAPI—caused a big drama when PEP 563 was _almost_ released in 3.10 and needed to be reverted at the last minute. I have a lot of thoughts on all the things related to this, but the short version is I would hate Airflow to become such projects. At the very leat, we should wait until the runtime aspects of type hints are discussed, decided on, and implemented, before making an effort toward related features.
   
   Has this opinion changed at all in the 3 years that have passed?
   
   I don't know enough about the Python org's intentions around type hints, and I don't expect changes to be made for my personal preference, but just anecdotally type hinting and more generally dataclasses are becoming more and more common in the data engineering world, having feedback in your editor as opposed to having to debug at run time is an exceptional developer workflow improvement, and XComArgs seem to make it almost pointless to type hint Airflow code at the moment because you end up with an LSP error on every single line that you call an airflow task.
   
   The two suggestions I've seen are 1) use cast, which defeats the point, and 2) use a MyPy plugin, which requires the developers to change tools and use a potentially unsupported plugin, I haven't checked recently but I saw an issue where it was mentioned that the plugin was moved to a dev folder rather than being distributed with MyPy by default since it negatively affected isort formatting.


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