Skip to content

None inferred as variable type from UninhabitedType #4104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JukkaL opened this issue Oct 12, 2017 · 3 comments
Closed

None inferred as variable type from UninhabitedType #4104

JukkaL opened this issue Oct 12, 2017 · 3 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 12, 2017

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.

@gvanrossum
Copy link
Member

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

@ilevkivskyi
Copy link
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).

@gvanrossum
Copy link
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
Projects
None yet
Development

No branches or pull requests

3 participants