Skip to content

Incompatible return value type with object in 0.950 #12687

@TylerYep

Description

@TylerYep

Bug Report

This did not error in previous versions.

To Reproduce

from typing import Generic, TypeVar

T = TypeVar("T")


class Animal(Generic[T]):
    pass


class Pooh(Animal[T]):
    pass


class Tigger(Animal[T]):
    pass


def build_friend(animal_type: str) -> Animal[T]:
    friend_map = {constructor.__name__: constructor for constructor in (Pooh, Tigger)}
    return friend_map[animal_type]()     
    # error: Incompatible return value type (got "object", expected "Animal[T]")  [return-value]

Expected Behavior

Expected to pass cleanly with no errors.

Actual Behavior

Errors with incompatible return value type

Your Environment

  • Mypy version used: 0.950
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files): strict=True
  • Python version used: 3.10.0
  • Operating system and version: Mac OS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-join-v-unionUsing join vs. using unions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions