MCPcopy Create free account
hub / github.com/PyCQA/flake8 / mutate_string

Function mutate_string

src/flake8/processor.py:435–454  ·  view source on GitHub ↗

Replace contents with 'xxx' to prevent syntax matching. >>> mutate_string('"abc"') '"xxx"' >>> mutate_string("'''abc'''") "'''xxx'''" >>> mutate_string("r'abc'") "r'xxx'"

(text: str)

Source from the content-addressed store, hash-verified

433# https://github.com/PyCQA/pycodestyle. The in-line comments were edited to be
434# more descriptive.
435def mutate_string(text: str) -> str:
436 """Replace contents with 'xxx' to prevent syntax matching.
437
438 >>> mutate_string('"abc"')
439 '"xxx"'
440 >>> mutate_string("'''abc'''")
441 "'''xxx'''"
442 >>> mutate_string("r'abc'")
443 "r'xxx'"
444 """
445 # NOTE(sigmavirus24): If there are string modifiers (e.g., b, u, r)
446 # use the last "character" to determine if we're using single or double
447 # quotes and then find the first instance of it
448 start = text.index(text[-1]) + 1
449 end = len(text) - 1
450 # Check for triple-quoted strings
451 if text[-3:] in ('"""', "'''"):
452 start += 2
453 end -= 2
454 return text[:start] + "x" * (end - start) + text[end:]

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected