Skip to content
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

Code is not cheked after some function calls: binder/inference bug #3994

Closed
ilevkivskyi opened this issue Sep 24, 2017 · 1 comment
Closed
Labels

Comments

@ilevkivskyi
Copy link
Member

Any code after an UninhabitedType is marked as unreachable in binder. This leads to dangerous behaviour together with how type inference currently works "in all uncertain situations infer uninhabited" (see also #3283 for discussion). For example no error is reported in this code:

from typing import TypeVar
T = TypeVar('T')

def f() -> T:
    ...

class C:
    f()
    1 + 'this is not checked'

def fun() -> None:
    f()
    1 + 'can do everything here'

if True:
    f()
    1 + 'whatever'

There are other function signatures (all involve type variables) that lead to this behaviour: type checking stops after a call to such function.

@elazarg
Copy link
Contributor

elazarg commented Sep 24, 2017

I think that in a dynamic settings ()->T should not be considered as returning Uninhabited. Similarly to how T->T is not necessarily the identity function.

JukkaL pushed a commit that referenced this issue Oct 20, 2017
Fixes #3994.

Currently code after inferred UninhabitedType is skipped. For example, no 
errors are shown for the commented lines in this code:

```
T = TypeVar('T')
def f(x: List[T]) -> T:
    ...

class C:
    x = f([])
    def m(self) -> str:
        return 42 # No error!

if bool():
    f([])
    1 + ''  # No error!
```

There are other scenarios in tests. With this PR errors are shown as expected, since UninhabitedTypes resulting from ambiguous inference don't influence binder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants