<p>mypy is very slow, pyright is fast but not quick enough in a large codebase, and tsc gives an immediate intellisense and type errors.</p>
<p>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.</p>
<p>Is it possible to implement a type-checking/inference for Python as fast as tsc?</p>

<static-typing><type-inference>
Type-checking Python vs Typescript
CC BY-SA 4.0
2024-04-09T07:18:21.590Z
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
Community Compiler
CC BY-SA 4.0
2024-04-09T07:44:18.860Z
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
Michael Homer
CC BY-SA 4.0
2024-04-09T12:53:42.010Z
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.
Jared Smith
CC BY-SA 4.0
2024-04-09T19:06:36.260Z
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.
tarzh
<p>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.</p>
<p>I was briefly attending the Python typing working group when I was at Facebook and I can tell you there is a <em>lot</em> 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 &quot;.&quot; 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.</p>
<p>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!</p>

CC BY-SA 4.0
2024-04-10T01:22:26.067Z
2024-04-10T01:33:18.783Z
2024-04-10T01:33:18.783Z
Eric Lippert
CC BY-SA 4.0
2024-04-10T17:36:49.523Z
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.
Jörg W Mittag
# Type-checking Python vs Typescript
Posted by: username_0 on 2024-04-09
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?
**Tags:** static-typing type-inference
> **Comments:**
> **username_1**: Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.  
> **username_2**: 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  
> **username_3**: 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.  
> **username_4**: 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.  
---
## 1 answers
### Answer by username_5 on 2024-04-10. Score: 4 | Accepted answer
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!
> **Comments:**
> **username_6** (2024-04-10): 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.  
---
