Skip to content

Regression with narrowing with TypeVar intersection #20628

@hauntsaninja

Description

@hauntsaninja
import os
from typing import Callable, TypeVar
T = TypeVar("T")
def auto_chmod(func: Callable[..., T], arg: str) -> T:
    if func == os.remove:
        return func(arg)
    raise

Regression introduced in #20492

Only shows up in real world code in #20602 , which looks something like this:

import os
from typing import Callable, TypeVar
T = TypeVar("T")
def auto_chmod(func: Callable[..., T], arg: str) -> T:
    if func in [os.unlink, os.remove]:
        return func(arg)
    raise

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions