Skip to content

None inferred as variable type from UninhabitedType #4104

Closed

Description

@JukkaL

The inferred type for x is unexpected (especially when using --strict-optional):

from typing import TypeVar

T = TypeVar('T')

def f() -> T: pass

x = f()
reveal_type(x)  # None

It would be better to require an annotation for x.

Activity

  1. gvanrossum commented on Oct 12, 2017

    @gvanrossum
    Member

    Why is the definition of f() not considered an error?

  2. ilevkivskyi commented on Oct 13, 2017

    @ilevkivskyi
    Member

    @gvanrossum

    Why is the definition of f() not considered an error?

    Because it is not unsafe. As discussed in #2885 we can't prohibit all possible useless annotations. Moreover now we have #4066, so that I think the way forward is to prohibit empty bodies (so that one can't make a body for such annotations).

  3. gvanrossum commented on Oct 13, 2017

    @gvanrossum
    Member

    It may not be unsafe, but I'm pretty sure that whenever you see that, the user misunderstands what type variables are on a fundamental level (e.g. they confuse them with type aliases).

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions