MCPcopy Index your code
hub / github.com/RustPython/RustPython / sub

Function sub

Lib/re/__init__.py:183–208  ·  view source on GitHub ↗

Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the Match object and mu

(pattern, repl, string, *args, count=_zero_sentinel, flags=_zero_sentinel)

Source from the content-addressed store, hash-verified

181_zero_sentinel = _ZeroSentinel()
182
183def sub(pattern, repl, string, *args, count=_zero_sentinel, flags=_zero_sentinel):
184 """Return the string obtained by replacing the leftmost
185 non-overlapping occurrences of the pattern in string by the
186 replacement repl. repl can be either a string or a callable;
187 if a string, backslash escapes in it are processed. If it is
188 a callable, it's passed the Match object and must return
189 a replacement string to be used."""
190 if args:
191 if count is not _zero_sentinel:
192 raise TypeError("sub() got multiple values for argument 'count'")
193 count, *args = args
194 if args:
195 if flags is not _zero_sentinel:
196 raise TypeError("sub() got multiple values for argument 'flags'")
197 flags, *args = args
198 if args:
199 raise TypeError("sub() takes from 3 to 5 positional arguments "
200 "but %d were given" % (5 + len(args)))
201
202 import warnings
203 warnings.warn(
204 "'count' is passed as positional argument",
205 DeprecationWarning, stacklevel=2
206 )
207
208 return _compile(pattern, flags).sub(repl, string, count)
209sub.__text_signature__ = '(pattern, repl, string, count=0, flags=0)'
210
211def subn(pattern, repl, string, *args, count=_zero_sentinel, flags=_zero_sentinel):

Callers

nothing calls this directly

Calls 4

lenFunction · 0.85
_compileFunction · 0.70
warnMethod · 0.45
subMethod · 0.45

Tested by

no test coverage detected