@@ -102,14 +102,20 @@ def diff_strings(first: str, second: str, /) -> str:
102102
103103# replaces all instances of `original` with `new` in string 
104104# unless it's preceded by a `-`, which indicates it's part of a command-line flag 
105- def  replace_library (string : str , original : str  =  "trio" , new : str  =  "anyio" ) ->  str :
105+ def  replace_library (
106+     string : str ,
107+     original : str  =  "trio" ,
108+     new : str  =  "anyio" ,
109+     replace_nursery : bool  =  False ,
110+ ) ->  str :
106111    def  replace_str (string : str , original : str , new : str ) ->  str :
107112        return  re .sub (rf"(?<!-){ original }  " , new , string )
108113
109-     if  original  ==  "trio"  and  new  ==  "anyio" :
110-         string  =  replace_str (string , "trio.open_nursery" , "anyio.create_task_group" )
111-     elif  original  ==  "anyio"  and  new  ==  "trio" :
112-         string  =  replace_str (string , "anyio.create_task_group" , "trio.open_nursery" )
114+     if  replace_nursery :
115+         if  original  ==  "trio"  and  new  ==  "anyio" :
116+             string  =  replace_str (string , "trio.open_nursery" , "anyio.create_task_group" )
117+         elif  original  ==  "anyio"  and  new  ==  "trio" :
118+             string  =  replace_str (string , "anyio.create_task_group" , "trio.open_nursery" )
113119    return  replace_str (string , original , new )
114120
115121
@@ -167,11 +173,18 @@ def check_autofix(
167173    # meaning it's replaced in visited_code, we also replace it in previous generated code 
168174    # and in the previous diff 
169175    if  base_library  !=  library :
176+         replace_nursery  =  "913"  in  test  or  "912"  in  test 
170177        previous_autofixed  =  replace_library (
171-             previous_autofixed , original = base_library , new = library 
178+             previous_autofixed ,
179+             original = base_library ,
180+             new = library ,
181+             replace_nursery = replace_nursery ,
172182        )
173183        autofix_diff_content  =  replace_library (
174-             autofix_diff_content , original = base_library , new = library 
184+             autofix_diff_content ,
185+             original = base_library ,
186+             new = library ,
187+             replace_nursery = replace_nursery ,
175188        )
176189
177190    # save any difference in the autofixed code 
@@ -281,7 +294,10 @@ def test_eval(
281294
282295    if  library  !=  magic_markers .BASE_LIBRARY :
283296        content  =  replace_library (
284-             content , original = magic_markers .BASE_LIBRARY , new = library 
297+             content ,
298+             original = magic_markers .BASE_LIBRARY ,
299+             new = library ,
300+             replace_nursery = "912"  in  test  or  "913"  in  test ,
285301        )
286302
287303        # if substituting we're messing up columns 
0 commit comments