[Python] mypy error:Incompatible types in assignment (expression has type "List[str]",...

Discussão em 'Python' iniciado por Stack, Abril 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have this very simple function:

    import datetime

    def create_url(check_in: datetime.date) -> str:
    """take date such as '2018-06-05' and transform to format '06%2F05%2F2018'"""
    _check_in = check_in.strftime("%Y-%m-%d")
    _check_in = _check_in.split("-")
    _check_in = _check_in[1] + "%2F" + _check_in[2] + "%2F" + _check_in[0]

    return f"https://www.website.com/?arrival={_check_in}"


    mypy throws the following error: error:Incompatible types in assignment (expression has type "List[str]", variable has type "str") for line 6 _check_in = _check_in.split("-"). I've tried renaming _check_inon line 6 but that makes no difference. This function works fine.

    Is this the expected behavior? How do I fix the error.

    Thanks!

    Continue reading...

Compartilhe esta Página