from pathlib import Path
from typing import Pattern
from typing import Optional
from typing import Match


def scan_file_for_pattern(file_path: Path, pattern: Pattern) -> Optional[Match]:
    """Looks for a specific pattern in a file."""
    if not file_path.exists():
        return None
    with open(str(file_path), "r", encoding="utf8") as f:
        text = f.read()
        return pattern.search(text)