Skip to content

issubclass() assertions not narrowing types #10680

Open
@jwodder

Description

@jwodder

Consider the following (contrived) code:

from typing import Type

def untyped_function():
    return int

def foo() -> Type[int]:
    x = untyped_function()
    assert issubclass(x, int)
    return x

Running mypy on this with the --warn-return-any option produces the error "Returning Any from function declared to return "Type[int]"", even though the assert issubclass should convince mypy that x is of type Type[int] and not an Any.

Your Environment

  • Mypy version used: 0.902
  • Mypy command-line flags: --warn-return-any
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.9.5
  • Operating system and version: macOS 11.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-narrowingConditional type narrowing / binder

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions