import os
import re

def mkdir_p(path):
  if not os.path.exists(path):
    os.makedirs(path)

def GetSymbolFileName(libName):
  # Guess the name of the .sym file on disk
  if libName[-4:] == ".pdb":
    return re.sub(r"\.[^\.]+$", ".sym", libName)
  return libName + ".sym"


import os

def mkdir_p(path):
  if not os.path.exists(path):
    os.makedirs(path)

def GetSymbolFileName(libName):
  # Guess the name of the .sym file on disk
  if libName[-4:] == ".pdb":
    return libName[:-4] + ".sym"
  return libName + ".sym"


Refactor out the re. It's not necessary to regex the replacement of an explicitly checked string in an explicit location. This should be simpler.
Refactor out the re. It's not necessary to regex the replacement of an explicitly checked string in an explicit location. This should be simpler.

  import os
- import re
  
  def mkdir_p(path):
    if not os.path.exists(path):
      os.makedirs(path)
  
  def GetSymbolFileName(libName):
    # Guess the name of the .sym file on disk
    if libName[-4:] == ".pdb":
-     return re.sub(r"\.[^\.]+$", ".sym", libName)
+     return libName[:-4] + ".sym"
    return libName + ".sym"
  
  
Refactor out the re. It's not necessary to regex the replacement of an explicitly checked string in an explicit location. This should be simpler.
## Code Before:
import os
import re

def mkdir_p(path):
  if not os.path.exists(path):
    os.makedirs(path)

def GetSymbolFileName(libName):
  # Guess the name of the .sym file on disk
  if libName[-4:] == ".pdb":
    return re.sub(r"\.[^\.]+$", ".sym", libName)
  return libName + ".sym"


## Instruction:
Refactor out the re. It's not necessary to regex the replacement of an explicitly checked string in an explicit location. This should be simpler.
## Code After:
import os

def mkdir_p(path):
  if not os.path.exists(path):
    os.makedirs(path)

def GetSymbolFileName(libName):
  # Guess the name of the .sym file on disk
  if libName[-4:] == ".pdb":
    return libName[:-4] + ".sym"
  return libName + ".sym"

