Live data from Hacker News

Pyre: A performant type-checker for Python 3

pyre-check.org

21–30 of 118 posts

Re: Pyre: A performant type-checker for Python 3

#23
post #20

PyCharm works well for me. Probably not as fancy as all this other stuff, but the type hints make the code easier to understand, and they help PyCharm help me by enabling it to find more errors and by enabling enhanced autocompletion.

PyCharm having type checking built in is excellent, but it is definitely the lowest quality out of the major 3 (Mypy, Pyright, Pyre) with respect to correctness.

Re: Pyre: A performant type-checker for Python 3

#24

Earlier quoted context omitted.

Last I checked, mypy struggled to represent recursive types. Think `JSON = Union[None, bool, str, float, int, List['JSON'], Dict[str, 'JSON']`. That's a bummer because recursive data types are darn handy. Worse, importing third party packages often fails silently and when you can get error messages they tend to be completely inactionable (I recall one error message which linked to a web page that had lots of details…

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'…

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)

Re: Pyre: A performant type-checker for Python 3

#25
post #2

Big discussion with over 500 comments from 3 years ago: https://news.ycombinator.com/item?id=17048446

So three years passed and static checkers have gotten even more traction. What's the best option for Python so far for small projects today? I tried mypy [1] before but it was a bit cumbersome to keep it checking my code. At work I use pytype [2]. It's good enough but that's only because someone else made a build system integration for me. Pyre's scan-all-the-files approach seems easier to get started. Is there any c…

have you had any problems using the open source version of pytype? we've tried to make it easy to just drop in to your setup.cfg and automatically analyse an entire project; if there are things that don't work we'd love bug reports for them!

Re: Pyre: A performant type-checker for Python 3

#26

Earlier quoted context omitted.

I've used mypy and pyright. Mypy generally "just works" for all the Python idioms I use, while pyright is less reliable. Pyright's VSCode integration, Pylance, provides a great auto complete experience. So I use Pyright for autocomplete in VSCode and mypy for type checking.

Last I checked, mypy struggled to represent recursive types. Think `JSON = Union[None, bool, str, float, int, List['JSON'], Dict[str, 'JSON']`. That's a bummer because recursive data types are darn handy. Worse, importing third party packages often fails silently and when you can get error messages they tend to be completely inactionable (I recall one error message which linked to a web page that had lots of details…

This is all true. So true infact that I wrote a huge article documenting this for people who are new to it: https://tshr.me/mypy

I'm planning to migrate this to my own blog soon.

Re: Pyre: A performant type-checker for Python 3

#27

Earlier quoted context omitted.

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'…

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: retur…

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.

Re: Pyre: A performant type-checker for Python 3

#28
post #10

As with package managers, there seem to be half a dozen different, competing type checkers for Python now...

Yeah and even worse they disagree about type errors! We really need a modern Python alternative. I don't know of any that don't give up the REPL / single file script features which are pretty huge advantages of Python to be honest.

It's radically different, but the language where I've had the most pleasant repl-driven experience is Elixir. Because of how it's error handling works it's even sane to debug with a repl into live production in some cases.

Re: Pyre: A performant type-checker for Python 3

#29
post #10

As with package managers, there seem to be half a dozen different, competing type checkers for Python now...

Yeah and even worse they disagree about type errors! We really need a modern Python alternative. I don't know of any that don't give up the REPL / single file script features which are pretty huge advantages of Python to be honest.

Node.js has a REPL, and there's nothing stopping you from putting your entire project into a single file.

Re: Pyre: A performant type-checker for Python 3

#30
post #10

As with package managers, there seem to be half a dozen different, competing type checkers for Python now...

Yeah and even worse they disagree about type errors! We really need a modern Python alternative. I don't know of any that don't give up the REPL / single file script features which are pretty huge advantages of Python to be honest.

All ML derived languages, Lisp based languages have REPL, you can put everything on one file if you feel like it, and they compile to native code.

Then there is Julia as well.

Post reply on HN