1616from rich .text import Text
1717from upath import UPath
1818
19+ from _pytask .coiled_utils import Function
20+ from _pytask .coiled_utils import extract_coiled_function_kwargs
1921from _pytask .collect_utils import create_name_of_python_node
2022from _pytask .collect_utils import parse_dependencies_from_task_function
2123from _pytask .collect_utils import parse_products_from_task_function
4648from _pytask .reports import CollectionReport
4749from _pytask .shared import find_duplicates
4850from _pytask .shared import to_list
51+ from _pytask .shared import unwrap_task_function
4952from _pytask .task_utils import COLLECTED_TASKS
5053from _pytask .task_utils import task as task_decorator
5154from _pytask .typing import is_task_function
@@ -311,15 +314,21 @@ def pytask_collect_task(
311314 )
312315
313316 markers = get_all_marks (obj )
314- collection_id = obj .pytask_meta ._id if hasattr (obj , "pytask_meta" ) else None
315- after = obj .pytask_meta .after if hasattr (obj , "pytask_meta" ) else []
316- is_generator = (
317- obj .pytask_meta .is_generator if hasattr (obj , "pytask_meta" ) else False
318- )
319317
320- # Get the underlying function to avoid having different states of the function,
321- # e.g. due to pytask_meta, in different layers of the wrapping.
322- unwrapped = inspect .unwrap (obj )
318+ if hasattr (obj , "pytask_meta" ):
319+ attributes = {
320+ ** obj .pytask_meta .attributes ,
321+ "collection_id" : obj .pytask_meta ._id ,
322+ "after" : obj .pytask_meta .after ,
323+ "is_generator" : obj .pytask_meta .is_generator ,
324+ }
325+ else :
326+ attributes = {"collection_id" : None , "after" : [], "is_generator" : False }
327+
328+ unwrapped = unwrap_task_function (obj )
329+ if isinstance (unwrapped , Function ):
330+ attributes ["coiled_kwargs" ] = extract_coiled_function_kwargs (unwrapped )
331+ unwrapped = unwrap_task_function (unwrapped .function )
323332
324333 if path is None :
325334 return TaskWithoutPath (
@@ -328,11 +337,7 @@ def pytask_collect_task(
328337 depends_on = dependencies ,
329338 produces = products ,
330339 markers = markers ,
331- attributes = {
332- "collection_id" : collection_id ,
333- "after" : after ,
334- "is_generator" : is_generator ,
335- },
340+ attributes = attributes ,
336341 )
337342 return Task (
338343 base_name = name ,
@@ -341,11 +346,7 @@ def pytask_collect_task(
341346 depends_on = dependencies ,
342347 produces = products ,
343348 markers = markers ,
344- attributes = {
345- "collection_id" : collection_id ,
346- "after" : after ,
347- "is_generator" : is_generator ,
348- },
349+ attributes = attributes ,
349350 )
350351 if isinstance (obj , PTask ):
351352 return obj
0 commit comments