Skip to content

Not None checks ignored when passing to a lambda #9076

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
ltworf opened this issue Jul 1, 2020 · 3 comments
Closed

Not None checks ignored when passing to a lambda #9076

ltworf opened this issue Jul 1, 2020 · 3 comments

Comments

@ltworf
Copy link

ltworf commented Jul 1, 2020

from typing import *

def f(p: Optional[str]) -> Callable[[str], bool]:
    assert p
    if p is None:
        raise Exception('asd')
    return lambda a: p.startswith(a)

This doesn't pass, despite the 2 checks to make sure that p is indeed a string.

@ltworf
Copy link
Author

ltworf commented Jul 1, 2020

It seems to work if instead of the lamda I use functools.partial

@kaste
Copy link

kaste commented Jul 1, 2020

This is a dupe of #4297

Note that most of the time lambda gives you more type safety than partial. Of course, partial gives you more programming safety. But, using it here you just mute the mypy error.

@JelleZijlstra
Copy link
Member

Closing as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants