@@ -392,32 +392,32 @@ def append_lines(
392392
393393def replace_patterns (
394394 path : Path ,
395- patterns : Union [str , Iterable [str ]],
396- repls : Union [str , Iterable [str ]],
395+ pattern : Union [str , Iterable [str ]],
396+ repl : Union [str , Iterable [str ]],
397397 regex : bool = True ,
398398) -> None :
399399 """Update a text file using regular expression substitution.
400400
401401 :param path: A Path object to the file to be updated.
402- :param patterns : A (list of) patterns to replace.
403- :param repls : A list of replacements.
402+ :param pattern : A (list of) patterns to replace.
403+ :param repl : A ( list of) replacements.
404404 or a function to map patterns to replacements.
405405 :param regex: If true, treat patterns as regular expression pattern;
406406 otherwise, perform exact matches.
407407 """
408408 if isinstance (path , str ):
409409 path = Path (path )
410410 text = path .read_text (encoding = "utf-8" )
411- if isinstance (patterns , str ):
412- patterns = [patterns ]
413- if isinstance (repls , str ):
414- repls = [repls ]
411+ if isinstance (pattern , str ):
412+ pattern = [pattern ]
413+ if isinstance (repl , str ):
414+ repl = [repl ]
415415 if regex :
416- for pattern , repl in zip (patterns , repls ):
417- text = re .sub (pattern , repl , text )
416+ for p , r in zip (pattern , repl ):
417+ text = re .sub (p , r , text )
418418 else :
419- for pattern , repl in zip (patterns , repls ):
420- text = text .replace (pattern , repl )
419+ for p , r in zip (pattern , repl ):
420+ text = text .replace (p , r )
421421 path .write_text (text , encoding = "utf-8" )
422422
423423
0 commit comments