1
$\begingroup$

mypy is very slow, pyright is fast but not quick enough in a large codebase, and tsc gives an immediate intellisense and type errors.

I do not know whether it is because Python has more complex type system, or different algorithm, or just more effort is put in tsc. Given that Typescript also has unions and generics, I think it should be achievable in Python too.

Is it possible to implement a type-checking/inference for Python as fast as tsc?

$\endgroup$
4
  • 1
    $\begingroup$ Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. $\endgroup$ Commented Apr 9 at 7:18
  • $\begingroup$ My suggestion is to make the question the one encapsulated in the second paragraph, and save the third paragraph for a later separate question, but either could be workable if that’s what you’re looking for $\endgroup$
    – Michael Homer
    Commented Apr 9 at 7:44
  • $\begingroup$ You're comparing two different things: you're talking about using a Python type checker in a large codebase but when referencing tsc you're talking about providing LSP feedback in a text editor. That being said, I don't have proof of this but the answer to your question is almost certainly money: Microsoft has poured millions and millions of USD into Typescript over the last 10 years (not to mention the community contributions) but Python type checkers tend to be more community efforts. $\endgroup$ Commented Apr 9 at 12:53
  • $\begingroup$ A more general question could be: what makes some dynamic languages easier to gradually type than others? And cite TypeScript vs typed Python as a potential example. $\endgroup$
    – tarzh
    Commented Apr 9 at 19:06

1 Answer 1

4
$\begingroup$

TypeScript was specifically designed by Anders to have fast IntelliSense; recall that he wrote an engine for Java back in the 1990s that could do a then-amazing million lines of code a second, and then spent a couple decades designing and implementing similar architectures for C# and VB -- leading a carefully chosen team of experts of course. Microsoft knows how to build teams that solve this problem.

I was briefly attending the Python typing working group when I was at Facebook and I can tell you there is a lot of interest in typing Python across the industry. What there is not is consensus on what important properties a type system must have that are common across all stakeholders. Building a type system that finds defects if allowed to run for minutes on checked-in code is very different than building a type system that does IntelliSense in under 30 milliseconds on code that is currently syntactically wrong because someone just pressed "." in an editor. There are a lot of type systems being built, to address the needs of the people putting in the time and effort to build them.

There's no in-principle reason why a Python type system that checks in between keystrokes as a user is typing in broken code could not be built. Someone is probably building one!

$\endgroup$
1
  • 1
    $\begingroup$ Microsoft is building the Pyright type checker and the Pylance extension for Visual Studio Code, which are now the official Python experience in Visual Studio Code. I believe that is pretty much what you are talking about. $\endgroup$ Commented Apr 10 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .