@@ -1475,27 +1475,18 @@ async def _closure():
14751475 return result
14761476
14771477
1478- _INIT_WRAPPED = "__workers_init_wrapped__"
1479-
1480-
14811478def _wrap_subclass (cls ):
14821479 # Override the class __init__ so that we can wrap the `env` in the constructor.
14831480 original_init = cls .__init__
14841481
14851482 def wrapped_init (self , * args , ** kwargs ):
1486- # Guard against double-wrapping in multi-level inheritance.
1487- # __init_subclass__ fires for every subclass, so each level installs
1488- # its own wrapped_init. The per-instance flag ensures ctx/env are
1489- # wrapped only once, by the outermost wrapped_init.
1490- if not hasattr (self , _INIT_WRAPPED ):
1491- args = list (args )
1492- if len (args ) > 0 :
1493- _pyodide_entrypoint_helper .patchWaitUntil (args [0 ])
1494- if issubclass (cls , DurableObject ):
1495- args [0 ] = DurableObjectContext (args [0 ])
1496- if len (args ) > 1 :
1497- args [1 ] = _EnvWrapper (args [1 ])
1498- setattr (self , _INIT_WRAPPED , True )
1483+ args = list (args )
1484+ if len (args ) > 0 :
1485+ _pyodide_entrypoint_helper .patchWaitUntil (args [0 ])
1486+ if issubclass (cls , DurableObject ):
1487+ args [0 ] = DurableObjectContext (args [0 ])
1488+ if len (args ) > 1 :
1489+ args [1 ] = _EnvWrapper (args [1 ])
14991490
15001491 original_init (self , * args , ** kwargs )
15011492
@@ -1542,7 +1533,8 @@ def __init__(self, ctx: "DurableObjectState", env: "Env"):
15421533 self .env = env
15431534
15441535 def __init_subclass__ (cls , ** _kwargs ):
1545- _wrap_subclass (cls )
1536+ if DurableObject in cls .__bases__ :
1537+ _wrap_subclass (cls )
15461538
15471539
15481540class WorkerEntrypoint :
@@ -1558,7 +1550,10 @@ def __init__(self, ctx: "ExecutionContext", env: "Env"):
15581550 self .env = env
15591551
15601552 def __init_subclass__ (cls , ** _kwargs : Any ):
1561- _wrap_subclass (cls )
1553+ # Make sure we do not apply the wrapper multiple times
1554+ # when inheriting from the base class
1555+ if WorkerEntrypoint in cls .__bases__ :
1556+ _wrap_subclass (cls )
15621557
15631558
15641559class WorkflowEntrypoint :
@@ -1574,5 +1569,6 @@ def __init__(self, ctx: "ExecutionContext", env: "Env"):
15741569 self .env = env
15751570
15761571 def __init_subclass__ (cls , ** _kwargs : Any ):
1577- _wrap_subclass (cls )
1572+ if WorkflowEntrypoint in cls .__bases__ :
1573+ _wrap_subclass (cls )
15781574 _wrap_workflow_step (cls )
0 commit comments