from typing import Optional
from typing import Tuple
import re


def _match_attribute(line: str) -> Optional[Tuple[str, str, str, str]]:
    """
    Try to match the given line with an attribute and return the name,
    type hint, value and inline comment (respectively) if a match was
    found.

    Args:
        line: the line of code that (may) contain an attribute declaration.

    Returns: a tuple with strings (name, hint, value, comment) or None.

    """
    attr_pattern = re.compile(
        r'^'
        r'\s*'
        r'([a-zA-Z_]+[a-zA-Z_0-9]*)'  # 1: Name.
        r'(\s*:\s*(\w+)\s*)?'  # 3: Type hint.
        r'\s*=\s*'
        r'(.+?)'  # 4: Value.
        r'\s*'
        r'(#\s*(.*?)\s*)?'  # 6: Inline comment.
        r'$'
    )
    match = attr_pattern.match(line)
    result = None
    if match:
        attr_name = match.group(1)
        hint = match.group(3)
        attr_value = match.group(4)
        inline_comments = match.group(6)
        result = attr_name, hint, attr_value, inline_comments
    return result