from typing import Tuple
from typing import Optional
import traceback
import re


def extract_from_stack(exc: BaseException) -> Tuple[Optional[str], Optional[str], Optional[str]]:
    """
    Extract minimal useful information from top of function stack.

    Returns:
        str: filename
        str: lineno
        str: function name
    """
    traceback_exception = traceback.TracebackException.from_exception(exc)
    stack_string = traceback_exception.stack.format()[-1]
    # File ".*", line n+, in s+\n
    prog = re.compile(r'File ".+/(\w+[.]py)", line (\d+), in (\w+)\n')
    match = prog.search(stack_string)
    if match:
        matches = match.groups()
        if len(matches) == 3:  # for mypy
            return matches[0], matches[1], matches[2]
    return None, None, None