I don't know if there's anything specifically stopping this, but from what I understand, the precise moment that a finalizer gets called is unspecified, so relying on any sort of behavior there is undefined and non-portable. Implementations like PyPy don't always use reference counting, so their garbage collection might get called some unspecified amount of time later.
I'm not familiar with Airflow, but would you be able to decorate the create() function to check for good return values? Something like : import functools : : def dag_initializer(func): : @functools.wraps(func) : def wrapper(): : with DAG(...) as dag: : result = func(dag) : del dag : if not isinstance(result, DAG): : raise ValueError(f"{func.__name__} did not return a dag") : return result : return wrapper : : @dag_initializer : def create(dag): : "some code here" _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/EBCLFYZLCTANUYSPZ55GFHG5I7DDTR76/ Code of Conduct: http://python.org/psf/codeofconduct/