@@ -64,7 +64,7 @@ class DeprecationRecord:
6464 deprecated_in : str | None
6565 path : Path
6666 line : int
67- kind : Literal ["decorator" , "warn_call" ]
67+ kind : Literal ["decorator" , "warn_call" , "cleanup_call" ]
6868 package : str
6969
7070
@@ -246,28 +246,47 @@ def _gather_warn_calls(
246246 else :
247247 continue
248248
249- if func_name != "warn_deprecated" :
250- continue
249+ if func_name == "warn_deprecated" :
250+ identifier_node = node .args [0 ] if node .args else None
251+ if identifier_node is None :
252+ continue
253+ identifier = ast .unparse (identifier_node )
251254
252- identifier_node = node .args [0 ] if node .args else None
253- if identifier_node is None :
254- continue
255- identifier = ast .unparse (identifier_node )
256-
257- removed_expr = _extract_kw (node , "removed_in" )
258- deprecated_expr = _extract_kw (node , "deprecated_in" )
259-
260- yield DeprecationRecord (
261- identifier = identifier ,
262- removed_in = _parse_removed_value (removed_expr , path = path , line = node .lineno ),
263- deprecated_in = _parse_deprecated_value (
264- deprecated_expr , path = path , line = node .lineno
265- ),
266- path = path ,
267- line = node .lineno ,
268- kind = "warn_call" ,
269- package = package ,
270- )
255+ removed_expr = _extract_kw (node , "removed_in" )
256+ deprecated_expr = _extract_kw (node , "deprecated_in" )
257+
258+ yield DeprecationRecord (
259+ identifier = identifier ,
260+ removed_in = _parse_removed_value (
261+ removed_expr , path = path , line = node .lineno
262+ ),
263+ deprecated_in = _parse_deprecated_value (
264+ deprecated_expr , path = path , line = node .lineno
265+ ),
266+ path = path ,
267+ line = node .lineno ,
268+ kind = "warn_call" ,
269+ package = package ,
270+ )
271+ elif func_name == "warn_cleanup" :
272+ identifier_node = node .args [0 ] if node .args else None
273+ if identifier_node is None :
274+ continue
275+ identifier = ast .unparse (identifier_node )
276+
277+ cleanup_expr = _extract_kw (node , "cleanup_by" )
278+
279+ yield DeprecationRecord (
280+ identifier = identifier ,
281+ removed_in = _parse_removed_value (
282+ cleanup_expr , path = path , line = node .lineno
283+ ),
284+ deprecated_in = None ,
285+ path = path ,
286+ line = node .lineno ,
287+ kind = "cleanup_call" ,
288+ package = package ,
289+ )
271290
272291
273292def _build_identifier (node : ast .AST ) -> str :
@@ -329,6 +348,14 @@ def _should_fail(current_version: str, record: DeprecationRecord) -> bool:
329348def _format_record (record : DeprecationRecord ) -> str :
330349 location = record .path .relative_to (REPO_ROOT )
331350 removed = record .removed_in if record .removed_in is not None else "(none)"
351+
352+ if record .kind == "cleanup_call" :
353+ return (
354+ f"- [{ record .package } ] { record .identifier } ({ record .kind } )\n "
355+ f" cleanup by: { removed } \n "
356+ f" defined at: { location } :{ record .line } "
357+ )
358+
332359 deprecated = (
333360 record .deprecated_in if record .deprecated_in is not None else "(unknown)"
334361 )
@@ -371,14 +398,34 @@ def main(argv: Sequence[str] | None = None) -> int:
371398 package_summaries .append ((package .name , current_version , len (records )))
372399
373400 if overdue :
374- print ("The following deprecated features have passed their removal deadline:\n " )
375- for record in overdue :
376- print (_format_record (record ))
377- print ()
378- print (
379- "Update or remove the listed features before publishing a version that "
380- "meets or exceeds their removal deadline."
381- )
401+ deprecated_items = [r for r in overdue if r .kind != "cleanup_call" ]
402+ cleanup_items = [r for r in overdue if r .kind == "cleanup_call" ]
403+
404+ if deprecated_items :
405+ print (
406+ "The following deprecated features have passed their removal "
407+ "deadline:\n "
408+ )
409+ for record in deprecated_items :
410+ print (_format_record (record ))
411+ print ()
412+
413+ if cleanup_items :
414+ print ("The following workarounds have passed their cleanup deadline:\n " )
415+ for record in cleanup_items :
416+ print (_format_record (record ))
417+ print ()
418+
419+ if deprecated_items :
420+ print (
421+ "Update or remove the listed features before publishing a version that "
422+ "meets or exceeds their removal deadline."
423+ )
424+ if cleanup_items :
425+ print (
426+ "Remove the listed workarounds before publishing a version that "
427+ "meets or exceeds their cleanup deadline."
428+ )
382429 return 1
383430
384431 for package_name , version , count in package_summaries :
0 commit comments