@@ -102,14 +102,20 @@ def diff_strings(first: str, second: str, /) -> str:
102
102
103
103
# replaces all instances of `original` with `new` in string
104
104
# 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 :
106
111
def replace_str (string : str , original : str , new : str ) -> str :
107
112
return re .sub (rf"(?<!-){ original } " , new , string )
108
113
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" )
113
119
return replace_str (string , original , new )
114
120
115
121
@@ -167,11 +173,18 @@ def check_autofix(
167
173
# meaning it's replaced in visited_code, we also replace it in previous generated code
168
174
# and in the previous diff
169
175
if base_library != library :
176
+ replace_nursery = "913" in test or "912" in test
170
177
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 ,
172
182
)
173
183
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 ,
175
188
)
176
189
177
190
# save any difference in the autofixed code
@@ -281,7 +294,10 @@ def test_eval(
281
294
282
295
if library != magic_markers .BASE_LIBRARY :
283
296
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 ,
285
301
)
286
302
287
303
# if substituting we're messing up columns
0 commit comments