Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have yet to successfully build a project with the strict mypy settings, without resorting to either turning some off or having to use an explicit Any. And a lot of the non-default settings are absolutely critical if you care about correctness.

Lack of recursive types has been a major deal breaker for me. If you have a class Foo that can construct a class Bar, and a class Bar that can construct a class Foo, you can't express that in mypy without Any-Generics.

To me, at this point, mypy is barely a linter, it's more of a "this helps my IDE autocomplete faster", and definitely not a type system.



I also struggle with Mypy's strict mode, but I think recursive types are different from classes that can construct each other. Mypy doesn't have any problem with the following code

    from __future__ import annotations


    class X:
        def __init__(self, value: int) -> None:
            self.value = value

        def to_y(self) -> Y:
            return Y(self.value)


    class Y:
        def __init__(self, value: int) -> None:
            self.value = value

        def to_x(self) -> X:
            return X(self.value)


    x = X(10).to_y().to_x()
    print(x.value)


Sorry, yes, that works. I should have been a little more explicit. This breaks down when Y is generic over X and X is generic over Y. IDK, I've had tons of problems with mutually recursive TypeVars, though my example was not of that - sorry.


This pretty much mirrors my mypy experience too. The only project I've ever successfully used it on was a single-file CLI tool that only used the stdlib.

And by "successfully" I mean "it ran at all". Every other thing I've thrown at it has caused it to crash. I quite like the concept, but implementation has been rather abysmal as far as I've seen. Has it improved in ~ the past year?


I've been using it recently, but just as a vscode plug in for type hints, I don't run any additional checks afterwards, but it seems to catch type errors before execution. But it's been cpu intensive in a wsl container on larger >2k line py files. I haven't tried many others tho, so not really sure if there are better options out there.


Not really, no.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: