You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mypy crashes if there is no 'function' or 'module' in builtins #2765
changed the title [-]Mypy crashes if there is no 'function' in builtins[/-][+]Mypy crashes if there is no 'function' or 'module' in builtins[/+]on Jan 27, 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.
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
Activity
[-]Mypy crashes if there is no `function` in `builtins`[/-][+]Mypy crashes if there is no 'function' in builtins[/+]vlasovskikh commentedon Jan 27, 2017
The same applies to
builtins.moduleandtypes.ModuleType.[-]Mypy crashes if there is no 'function' in builtins[/-][+]Mypy crashes if there is no 'function' or 'module' in builtins[/+]JukkaL commentedon Jan 31, 2017
The reason mypy has these fake definitions in builtins is to get tidier error messages. We could instead translate
types.FunctionTypetofunctionwhen generating messages.moduleis similar.vlasovskikh commentedon Jan 31, 2017
Having
functionandmodulein builtins results in false negatives where a type checkers acceptsfunctionandmodulein the user code as built-ins.ilevkivskyi commentedon Apr 13, 2017
The module part of this issue is fixed by #3107
vlasovskikh commentedon Sep 2, 2019
I believe
functionis no longer an issue as well, since it has been renamed to__function.ilevkivskyi commentedon Sep 2, 2019
@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__functionfew month ago.So I think this is something still worth fixing. I would prefer to use
types.FunctionTypeas a fallback for functions (or othertypesclasses 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 declaredCallable, see e.g. a hot discussion in #5958JelleZijlstra commentedon Apr 3, 2022
This is essentially the same as #8240 (thanks Alex for pointing me to it)