

def fix_requirements(f):
    requirements = []
    before = []
    after = []
    for line in f:
        before.append(line)
        if ((not len(requirements)) or (requirements[(- 1)].value is not None)):
            requirements.append(Requirement())
        requirement = requirements[(- 1)]
        if ((len(requirements) == 1) and (line.strip() == b'')):
            if (len(requirement.comments) and requirement.comments[0].startswith(b'#')):
                requirement.value = b'\n'
            else:
                requirement.comments.append(line)
        elif (line.startswith(b'#') or (line.strip() == b'')):
            requirement.comments.append(line)
        else:
            requirement.value = line
    for requirement in sorted(requirements):
        for comment in requirement.comments:
            after.append(comment)
        before.append(requirement.value)
    before_string = b''.join(before)
    after_string = b''.join(after)
    if (before_string == after_string):
        return 0
    else:
        f.seek(0)
        f.write(after_string)
        f.truncate()
        return 1

dataset/ETHPy150Open pre-commit/pre-commit-hooks/pre_commit_hooks/requirements_txt_fixer.py fix_requirements/VarMisuse@228/256 `after`->`before`