@@ -102,23 +102,30 @@ def _collect_from_tasks(session: Session) -> None:
102
102
obj = raw_task ,
103
103
)
104
104
105
- if not callable (raw_task ):
106
- msg = "Not a function."
107
- raise ValueError (msg )
105
+ if callable (raw_task ):
106
+ if not hasattr (raw_task , "pytask_meta" ):
107
+ raw_task = task_decorator ()(raw_task ) # noqa: PLW2901
108
+
109
+ try :
110
+ path = get_file (raw_task )
111
+ except (TypeError , OSError ):
112
+ path = None
113
+ else :
114
+ if path .name == "<stdin>" :
115
+ path = None # pragma: no cover
108
116
109
- if not hasattr (raw_task , "pytask_meta" ):
110
- raw_task = task_decorator ()(raw_task ) # noqa: PLW2901
117
+ # Detect whether a path is defined in a Jupyter notebook.
118
+ if is_jupyter () and "ipykernel" in path .as_posix () and path .suffix == ".py" :
119
+ path = None # pragma: no cover
111
120
112
- path = get_file (raw_task )
113
- if path .name == "<stdin>" :
114
- path = None
121
+ name = raw_task .pytask_meta .name
115
122
116
- # Detect whether a path is defined in a Jupyter notebook.
117
- if is_jupyter () and "ipykernel" in path .as_posix () and path .suffix == ".py" :
123
+ # When a task is not a PTask and a callable, set arbitrary values and it will
124
+ # pass without errors and not collected.
125
+ else :
126
+ name = ""
118
127
path = None
119
128
120
- name = raw_task .pytask_meta .name
121
-
122
129
report = session .hook .pytask_collect_task_protocol (
123
130
session = session ,
124
131
reports = session .collection_reports ,
0 commit comments