Skip to content

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

Closed

Description

@vlasovskikh

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

Activity

  1. changed the title [-]Mypy crashes if there is no `function` in `builtins`[/-] [+]Mypy crashes if there is no 'function' in builtins[/+] on Jan 27, 2017
  2. vlasovskikh commented on Jan 27, 2017

    @vlasovskikh
    MemberAuthor

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

  3. 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
  4. JukkaL commented on Jan 31, 2017

    @JukkaL
    Collaborator

    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.

  5. vlasovskikh commented on Jan 31, 2017

    @vlasovskikh
    MemberAuthor

    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.

  6. ilevkivskyi commented on Apr 13, 2017

    @ilevkivskyi
    Member

    The module part of this issue is fixed by #3107

  7. added and removed
    bugmypy got something wrong
    on May 19, 2018
  8. vlasovskikh commented on Sep 2, 2019

    @vlasovskikh
    MemberAuthor

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

  9. ilevkivskyi commented on Sep 2, 2019

    @ilevkivskyi
    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

  10. JelleZijlstra commented on Apr 3, 2022

    @JelleZijlstra
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions