Skip to content

Mypy crashes if there is no 'function' or 'module' in builtins #2765

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
vlasovskikh opened this issue Jan 27, 2017 · 7 comments
Closed

Mypy crashes if there is no 'function' or 'module' in builtins #2765

vlasovskikh opened this issue Jan 27, 2017 · 7 comments
Labels
affects-typeshed Anything that blocks a typeshed change crash priority-1-normal

Comments

@vlasovskikh
Copy link
Member

vlasovskikh commented Jan 27, 2017

You can use types.FunctionType instead of builtins.function. See the original crash in the CI results here python/typeshed#876.

@vlasovskikh vlasovskikh changed the title Mypy crashes if there is no function in builtins Mypy crashes if there is no 'function' in builtins Jan 27, 2017
@vlasovskikh
Copy link
Member Author

vlasovskikh commented Jan 27, 2017

The same applies to builtins.module and types.ModuleType.

@vlasovskikh vlasovskikh changed the title Mypy crashes if there is no 'function' in builtins Mypy crashes if there is no 'function' or 'module' in builtins Jan 27, 2017
@JukkaL JukkaL added bug mypy got something wrong priority-1-normal labels Jan 31, 2017
@JukkaL
Copy link
Collaborator

JukkaL commented Jan 31, 2017

The reason mypy has these fake definitions in builtins is to get tidier error messages. We could instead translate types.FunctionType to function when generating messages. module is similar.

@vlasovskikh
Copy link
Member Author

Having function and module in builtins results in false negatives where a type checkers accepts function and module in the user code as built-ins.

@ilevkivskyi
Copy link
Member

The module part of this issue is fixed by #3107

@JukkaL JukkaL added crash and removed bug mypy got something wrong labels May 19, 2018
@vlasovskikh
Copy link
Member Author

I believe function is no longer an issue as well, since it has been renamed to __function.

@ilevkivskyi
Copy link
Member

@vlasovskikh class function: ... is still defined here https://github.com/python/typeshed/blob/master/stdlib/2and3/builtins.pyi#L876, there are some function arguments that has ben renamed to __function few month ago.

So I think this is something still worth fixing. I would prefer to use types.FunctionType as a fallback for functions (or other types classes depending on kind of callable we deal with, like bound method, unbound method, etc.). There is however subtle question of what should be the fallback for user declared Callable, see e.g. a hot discussion in #5958

@JelleZijlstra
Copy link
Member

This is essentially the same as #8240 (thanks Alex for pointing me to it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-typeshed Anything that blocks a typeshed change crash priority-1-normal
Projects
None yet
Development

No branches or pull requests

5 participants