Thanks to visit codestin.com
Credit goes to github.com

Skip to content

regression: typevar with bound and type check causes narrowing to nothing #10605

Description

@KotlinIsland

To Reproduce

from typing import TypeVar, Type


class A:
    a: int = 1


T = TypeVar("T", bound=A)


def foo(t: Type[T], a: A) -> None:
    if type(a) is t:
        reveal_type(a) # <nothing>, with 0.8xx it was A
        a.a #  error: <nothing> has no attribute "a"

Expected Behavior

should not be narrowed to nothing, should be narrowed to A

Your Environment

  • Mypy version used: 0.900 and 0.8xx
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): no
  • Python version used: 3.10
  • Operating system and version: Windows 10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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