File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
src/refiners/fluxion/layers Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -609,6 +609,7 @@ def replace(
609
609
new_module ._set_parent (self )
610
610
if isinstance (old_module , ContextModule ):
611
611
old_module ._set_parent (old_module_parent )
612
+ self ._register_provider ()
612
613
613
614
def structural_copy (self : TChain ) -> TChain :
614
615
"""Copy the structure of the Chain tree.
Original file line number Diff line number Diff line change
1
+ import refiners .fluxion .layers as fl
2
+ from refiners .fluxion .adapters .adapter import Adapter
3
+ from refiners .fluxion .context import Contexts
4
+
5
+
6
+ class ContextAdapter (fl .Chain , Adapter [fl .Chain ]):
7
+ def __init__ (self , target : fl .Chain ):
8
+ with self .setup_adapter (target ):
9
+ super ().__init__ (
10
+ fl .Lambda (lambda : 42 ),
11
+ fl .SetContext ("foo" , "bar" ),
12
+ )
13
+
14
+
15
+ class ContextChain (fl .Chain ):
16
+ def init_context (self ) -> Contexts :
17
+ return {"foo" : {"bar" : None }}
18
+
19
+
20
+ def test_adapter_can_access_parent_context ():
21
+ chain = ContextChain (fl .Chain (), fl .UseContext ("foo" , "bar" ))
22
+ adaptee = chain .layer ("Chain" , fl .Chain )
23
+ ContextAdapter (adaptee ).inject (chain )
24
+
25
+ assert chain () == 42
You can’t perform that action at this time.
0 commit comments