Explanation: Python is a programming language. Numpy is a library for python that makes it possible to run large computations much faster than in native python. In order to make that possible, it needs to keep its own set of data types that are different from python’s native datatypes, which means you now have two different bool types and two different sets of True and False. Lovely.

Mypy is a type checker for python (python supports static typing, but doesn’t actually enforce it). Mypy treats numpy’s bool_ and python’s native bool as incompatible types, leading to the asinine error message above. Mypy is “technically” correct, since they are two completely different classes. But in practice, there is little functional difference between bool and bool_. So you have to do dumb workarounds like declaring every bool values as bool | np.bool_ or casting bool_ down to bool. Ugh. Both numpy and mypy declared this issue a WONTFIX. Lovely.

  • Daniel Quinn@lemmy.ca
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    4 months ago

    Honestly, after having served on a Very Large Project with Mypy everywhere, I can categorically say that I hate it. Types are great, type checking is great, but applying it to a language designed without types in mind is a recipe for pain.

      • scrion@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        I wholeheartedly agree. The ability to describe (in code) and validate all data, from config files to each and every message being exchanged is invaluable.

        I’m actively looking for alternatives in other languages now.

        • expr@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          4 months ago

          You’re just describing parsing in statically-typed languages, to be honest. Adding all of this stuff to Python is just (poorly) reinventing the wheel.

          Python’s a great language for writing small scripts (one of my favorite for the task, in fact), but it’s not really suitable for serious, large scale production usage.

          • renzev@lemmy.worldOP
            link
            fedilink
            arrow-up
            1
            ·
            4 months ago

            Gradual typing isn’t reinventing the wheel, it’s a new paradigm. Statically typed code is easier to write and harder to debug. Dynamically typed code is harder to debug, but easier to write. With gradual typing, the idea is that you can first write dynamic code (easier to write), and then – wait for it – GRADUALLY turn it into static code by adding type hints (easier to debug). It separates the typing away from the writing, meaning that the programmer doesn’t have to multitask as much. If you know what you’re doing, mypy really does let you eat your cake and keep it too.

    • folkrav@lemmy.ca
      link
      fedilink
      arrow-up
      2
      ·
      4 months ago

      Adding types on an untyped project is hell. Greenfield stuff is usually pretty smooth sailing as far as I’m concerned…