from typing import TextIO
from typing import Dict


def read_rank_file(input_fh: TextIO, max_records=-1) -> Dict[str, int]:
    """Reads lines and returns a dictionary where each key is a line and each value is the rank / line number.

    Repeated lines are ignored.
    """
    output_ranks = {}
    line_number = 1
    for line in input_fh:
        text = line.strip()
        if text not in output_ranks:
            output_ranks[text] = line_number
        line_number += 1
        if line_number > max_records > 0:
            break
    return output_ranks