Skip to content

assert and isinstance type inference #475

Closed

Description

@JukkaL

This code should be accepted by mypy:

def f(x: Union[int, str]) -> None:
    assert isinstance(x, int)
    x + 1  # type of x is int, so this should be okay

The type type checker should know about type assertions.

Activity

  1. JukkaL commented on Oct 12, 2014

    @JukkaL
    CollaboratorAuthor

    This could sometimes be used as an arguably more Pythonic replacement for casts.

  2. added this to the milestone on Mar 23, 2016
  3. gvanrossum commented on Mar 23, 2016

    @gvanrossum
    Member

    I found a bunch of occurrences of this in our server code; bumping priority to 0.3.2.

  4. added a commit that references this issue on Apr 8, 2016
    e14ee0b
  5. added a commit that references this issue on Apr 8, 2016
    848f821
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions