@@ -1648,19 +1648,19 @@ def _attempt_delivery_of_any_pending_cancel(self) -> None:
16481648 if not self ._cancel_status .effectively_cancelled :
16491649 return
16501650
1651- if (reason := self ._cancel_status ._scope ._cancel_reason ) is not None :
1652- cancelled = Cancelled ._create (
1653- source = reason .source ,
1654- reason = reason .reason ,
1655- source_task = reason .source_task ,
1656- )
1657- else :
1658- cancelled = Cancelled ._create (source = "unknown" , reason = "misnesting" )
1651+ reason = self ._cancel_status ._scope ._cancel_reason
1652+
1653+ def raise_cancel () -> NoReturn :
1654+ if reason is None :
1655+ raise Cancelled ._create (source = "unknown" , reason = "misnesting" )
1656+ else :
1657+ raise Cancelled ._create (
1658+ source = reason .source ,
1659+ reason = reason .reason ,
1660+ source_task = reason .source_task ,
1661+ )
16591662
1660- self ._attempt_abort (RaiseCancel (cancelled ))
1661- # Clear reference to pass gc tests. `RaiseCancel` keeps the `Cancelled`
1662- # alive until it's used.
1663- del cancelled
1663+ self ._attempt_abort (raise_cancel )
16641664
16651665 def _attempt_delivery_of_pending_ki (self ) -> None :
16661666 assert self ._runner .ki_pending
@@ -1674,17 +1674,6 @@ def raise_cancel() -> NoReturn:
16741674 self ._attempt_abort (raise_cancel )
16751675
16761676
1677- class RaiseCancel :
1678- def __init__ (self , cancelled : Cancelled ) -> None :
1679- self .cancelled = cancelled
1680-
1681- def __call__ (self ) -> NoReturn :
1682- try :
1683- raise self .cancelled
1684- finally :
1685- del self .cancelled
1686-
1687-
16881677################################################################
16891678# The central Runner object
16901679################################################################
0 commit comments