Skip to content

TypeIs does not work as a method/classmethod #1569

@carljm

Description

@carljm

In this snippet all reveal_type should reveal int; currently all but the first reveal object.

from typing import TypeIs

def is_int(val: object) -> TypeIs[int]:
  return isinstance(val, int)

class A:
  def is_int(self, val: object) -> TypeIs[int]:
    return isinstance(val, int)

  @classmethod
  def is_int2(cls, val: object) -> TypeIs[int]:
    return isinstance(val, int)

def _(x: object):
  if is_int(x):
    reveal_type(x)

  if A().is_int(x):
    reveal_type(x)

  if A().is_int2(x):
    reveal_type(x)

  if A.is_int2(x):
    reveal_type(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnarrowingrelated to flow-sensitive type narrowingtyping semanticstyping-module features, spec compliance, etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions