Skip to content

Unions of collectively valid argument types not accepted by @overload groups #3556

Closed
@rkr-at-dbx

Description

@rkr-at-dbx

This fails:

import re
from typing import Union, Pattern

def f(pattern):
    # type: (Union[str, Pattern[str]]) -> None
    re.search(pattern, "")

example.py:6: error: Argument 1 to "search" has incompatible type "Union[str, Pattern[str]]"; expected "unicode"

However, this passes without comment:

def g(pattern):
    # type: (Union[str, Pattern[str]]) -> None
    if isinstance(pattern, str):
        re.search(pattern, "")
    else:
        re.search(pattern, "")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions