10 ms·
Pyright: Static type checker for Python
- MapleWalnut 8y agoA comparison with mypy would be helpful.
- airstrike 8y agoFrom the README > Pyright is typically 5x or more faster than mypy and other type checkers that are written in Python. It is meant for large Python source bases. It can run in a “watch” mode and performs fast incremental updates when files are modified.
- berti 8y ago> Pyright is written in TypeScript and runs within node. It does not require a Python environment or imported third-party packages to be installed. I know which of those environments I would prefer... it's not node. It makes total sense for VS Code though, so fair enough.
- o10449366 8y agoI could see this being nice if you work within VSCode, have to juggle many Python versions, and already have Node installed, but I've personally had no issues with speed or configurability with mypy and pyenv. I think it's an interesting project, but probably half-baked at this point.
- deleted 8y ago[deleted]
- anurag 8y agoMicrosoft, Facebook, and Google all have their own Python type checkers now. * https://github.com/google/pytype https://github.com/google/pytype * https://github.com/facebook/pyre-check https://github.com/facebook/pyre-check
- Rotareti 8y agoDon't forget the one from Dropbox: * https://github.com/python/mypy https://github.com/python/mypy
- stonecharioteer 8y agoThe one blessed by Guido, you mean.
- gpshead 8y agoMyPy is not owned by Dropbox. They use it and many significant contributors work there, so it is easy to get this impression. But it was started before that happened.
- Too 8y agoJust in line with the zen of python: There should be one-- and preferably only one --obvious way to do it.
- akubera 8y agoI just installed it. It gives red squiggly lines under variables that haven't been assigned (typos) and for incorrect methods on variables it can type-deduce. This is without me adding any typing-hints to the script I'm working on. Only issue I see immediately is it does not use the default sys.path that the vs-code-configured python interpreter uses, so it cannot resolve some of the packages I'm using. But overall, very nice.
- staticassertion 8y agoIs mypy not open source? Why not collaborate? Mypy performance improvements are something that would be welcomed.
- pvg 8y agoIt's the second item in the README - one of the goals is no dependency on Python.
- staticassertion 8y agoAh, I just searched for "mypy" and saw the performance bit. Seems kind of odd, I see the vscode justification but if you're running this, having a dependency on Python seems like a low bar?
- pvg 8y agoI imagine the biggest driver/customer here is VS Code and then it becomes about adding such a dependence to VS Code which they probably don't want.
- seanwilson 8y agoIsn't "No Dependency on Python Environment" a strange goal? Surely if you were going to depend on anything for a Python tool it would be that you've got Python installed? I could understand if the goal was "to easily run within VS Code".
- syastrov 8y agoMypy performance is quite good in daemon mode for incremental updates. The recently released mypy-mypyc (AOC compiled version) gave me a 6x performance improvement on typechecking a large project.
- staticassertion 8y agoYeah, the daemon is way better for sure.
- xiaodai 8y agoFlogging a dead horse
- StaticRedux 8y agoMicrosoft, please make one for Ruby! C# vet and lover of VS and VS Code, now working on a legacy Ruby/Rails code base and hating a new life of lifecycle callbacks, fat controllers, fat models, magic methods, and un-upgradeable gems. Ugh.
- realusername 8y agoIt's a shame Crystal isn't taking off that much, I use it for some personal projects and it's such a joy to work with thanks to the static typing, unfortunately the community is a bit too small. A static-typed ruby is just the best thing I can wish personally.
- save_ferris 8y agoStripe is working on one called sorbet. The playground[0] is available, but to my knowledge the gem hasn't dropped just yet. [0] https://sorbet.run/ https://sorbet.run/
- hardwaresofton 8y agoStripe has one called Sorbet[0] (StrangeLoop2018 had a good talk[1] on it) that hasn't been released yet but hopefully will be soon. There's also soutaro/steep[2] which looks really promising and is available now. [0]: https://sorbet.run https://sorbet.run [1]: https://www.youtube.com/watch?v=uFFJyp8vXQI https://www.youtube.com/watch?v=uFFJyp8vXQI (slides: https://sorbet.run/talks/StrangeLoop2018 https://sorbet.run/talks/StrangeLoop2018) [2]: https://github.com/soutaro/steep https://github.com/soutaro/steep
- jrs95 8y agoRails has so much metaprogramming that static typing isn't really going to get you very far. Type checkers and linters won't know what the hell is going on.
- wrmsr 8y ago+1. ruby is by a good degree the hardest language to statically analyze that ive ever worked significantly with. type anns fit python relatively well due to it's philosophy being pretty much the direct opposite of ruby's: "explicit > implicit" vs "having a conversation" ed: to the degree that the man himself is adamantly against them in his language (except as perf hints) https://bugs.ruby-lang.org/issues/9999#note-13 https://bugs.ruby-lang.org/issues/9999#note-13
- scrollaway 8y agoI'm excited; this looks better than Pyre. It being in Typescript is ironically enough a pretty big deal. I think they're clearly writing this for vscode, right? I hope they are at least. Having spent the last decade and half writing Python code, I have completely stopped enjoying writing Python code (even typed Python) because of how good TypeScript and the VSCode typescript experience is. It doesn't even sort of compare. At this point I just want pretty much the same thing that happened to JS to happen to Python: For MS to make a Python superset with good type hinting (not the atrocious pep484 syntax) which compiles down to Python. … and wasm. Which compiles down to Python and wasm.
- joshuamorton 8y agoWhat's wrong with the pep 484 syntax in your view?
- uryga 8y agoit's not all bad but doing generic types is annoying because you have to do from typing import TypeVar T = TypeVar('T') in every module where you want to parametrize a type. (not sure how that works with 3.6+'s unevaluated annotations. that's what my linter thinks) also callable types are really ugly... this: Callable[[Foo, Bar], Baz] vs something like `(Foo, Bar) -> Baz` is just yuck putting constraints on a type is pretty ugly too iirc, i think it looks something like F = TypeVar(bound=Foo) def bar(a: F, b: F) -> F: ... hacking type annotations into the language's existing syntax is hard :(
- joshuamorton 8y agoI actually find this a feature. If you have a function that takes `(Foo, Bar) -> Baz`, What you really have is a function that takes in a FoobarBazifier. So name your function-interface: FoobarBazifier = Callable[[Foo, Bar], Baz] def my_func(cb: FoobarBazifier) -> Baz: ... This is pythonic, in the same way that preferring named functions over lambdas (and therefore not having a single character lambda syntax) is pythonic. Its controversial and people dislike it, but it is nice. It also has the side effect of letting you Subclass the interface if you want to (via NewType), so that if you have multiple functions that match the same signature but fulfill different interfaces, you can name the interfaces differently and use them in different places. Java mostly enforces this because you have to define an explicit interface and class for your callbacks (or you did until java 8), this is essentially the same thing, but with 1 line of boilerplate instead of 25 across 3 files.
- Rotareti 8y agoNow that we have type hints and statically typing in Python, I hope to see an open source Python compiler, that improves performance and produces single file binaries.
- MikeTheGreat 8y agoNo idea if this improves performance (and it's definitely not a compiler), but Pyz produces single files from your Python code: https://pypi.org/project/pyz/ https://pypi.org/project/pyz/
- sjellis 8y agoNuitka has been around for a few years: https://nuitka.net/ https://nuitka.net/ AIUI, this was basically a one-person effort for a long time, but the project is now growing.
- adaszko 8y agoI wish there was one too, but programmer-oriented types are not the same thing as machine-oriented types. Compiling to fast code requires the latter one: types like u32, not Dict[String, int]. Current Python typing efforts tend to focus on programmer-oriented types.
- gpshead 8y agoLook up PyOxidizer. But also look at MyPy's internal MyPyC if you want something that uses type information for some speedups.
- formalsystem 8y agoDoes this work typecheck matrix operations?
- roel_v 8y agoCan this be run in real time in VSCode? How hard would it be to write a vim plugin for this? I haven't done any vim scripting in a while - is it possible nowadays to run a process asynchronously, so that you could essentially run this tool on every keystroke?
- anthonybullard 8y agoI don't know about regular vim, but you could do this with NeoVim.
- c256 8y agoI believe that vim supports the language server protocol via a (some?) plugin(s), and that pyrite provides a lsp mode, so you should be able to use them together. Note that you would be running vim and node to write python code, which seems like a lot of different languages to me, but I’m mostly an emacs person, so...
- externalreality 8y agoI think this is great! Static typing is such a blessing. This one looks very high quality. Static typing helps me read code and helps the compiler do static analysis. What's not to like?
- z3t4 8y agoUnnecessary annotations, and compile step. No runtime guarantees. More work to rewrite and iterate although tooling makes up for it. Easier to write bad code due to less need to understand the interfaces. Harder to write any code although that might be a feature.
- joshuamorton 8y agoWut? No modern type system gives you runtime gaurantees (c++, Java, rust all erase in various ways). Interfaces are more clear.
- z3t4 8y agoIn JS I do my own (runtime) checks. People make fun of me and call it poor mans type checker. But I actually think I'm better then a typechecker to give nice error messages and know where more regious checks are needed. When you already do tests and defensive programming, static typing adds very little, it just gets in the way. Requiring others to skim through the code they are calling in order to understand it i think is a feature of dynamic languages. The better you understand the code the fewer errors you will make.
- externalreality 8y agoI don't know if any of that is true. The annotations actually help me to understand the code. I actually find it easy to rewrite and iterate with type annotations which are like machine checked comments. I think the purpose of the tool is to make it harder to write "bad" code, unless you mean "bad" in the aesthetic sense then I can't see how that is true either. In general I find it easier to write code since its easier to keep track of what the data looks like. What do you mean by interfaces? But then this is an argument that I don't have much time for and too much time has been spent on it already. Lets just say that if there are many major companies that felt the need to invest in a type system for a popular languages that don't have one, then there might be something too it.
- fineoldcannibal 8y agoAs someone who has worked with Eric Traut (the primary author of this from what I can see) in a previous life, I will say you can take this to the bank any day of the week. One of the best developers out there
- person_of_color 8y agoHow does he decide what to work on?
- philonoist 8y agoBut why does each company have one for their own[0]? [0]news.ycombinator.com/item?id=19473944
- ilovecaching 8y agoI still don't understand adding type checkers to dynamic languages beyond Javascript, where there was no other alternative. I view the gradual type checker craze as an admission that dynamically typed languages are a failed experiment. So why would you not just switch to a language that's designed with static typing in mind.
- Scarbutt 8y agoExisting code bases.
- c256 8y agoIn addition to the (extremely pertinent) answer above, there are advantages to dynamically typed languages in some cases, so it shouldn’t be surprising/confusing that sometimes “dynamic typing plus optional type checking with zero run-time overhead” is the best (or at least very good) of both worlds.
- quickthrower2 8y agoEcosystems
- zem 8y agothink about it the other way, and it's an admission that statically typed languages are a failed experiment because sometimes you really want to tell the typechecker "look, i can't prove this at compile time but it is correct", i.e. not have types in your code. the designer of the stanza language has a good writeup on why stanza uses optional types: http://lbstanza.org/optional_typing.html http://lbstanza.org/optional_typing.html
- umanwizard 8y agoWell not every statically typed language is so absolutist. In C/C++ you are perfectly welcome to cast things if you know you can prove things the typechecker can't.
- etatoby 8y agoFlame mode on. Can anybody explain to me why people seem to prefer using unsafe and interpreted/slow languages (Python, Ruby, Javascript... which is only fast now because companies have invested millions on it) and then spend a ton of resources writing "type checkers" for these inherently unsafe languages (Typescript, Pyre, Pyright) Why don't they simply use languages that are already safe and fast by design? (Rust, OCaml...)
- joatmon-snoo 8y agoThere are many, many libraries that I work with that are written in Python. Things for which a single script was once sufficient, then a few of them, and eventually multiple thousands of lines of code. I'm not going to spend years reimplementing that same logic in some other language. I'm going to build on top of it. Maybe I'll need to make changes to some of the underlying code. Better tooling - which is exactly what type checkers are - makes my life much, much easier and makes me much more productive. Besides, all these languages exist for a reason - you choose the tool appropriate for the problem. "safe and fast" does not make a language automatically better for a problem.
- jaabe 8y agoThe most important aspect of development in most companies is the developer him/herself. It’s typically also the most expensive resource tied to development. At least if you look at it from a management perspective. This means that it’s extremely risky to build things in hipster languages because the pool from which you can hire is extremely small. It also means you’ll have to spend a lot of money building tools and libraries that are “just” available in more popular languages. On top of that, most companies don’t need to scale things to the point that Netflix does, and even if you do, PHP was good enough to run Facebook before PHP got fast, Python was good enough to run Reddit, Node is good enough to run Netflix and Ruby was good enough to run Github. I mean, why would you ever chose Rust for your project from a business/management perspective? To save a few bucks on iron while increasing your development costs by hundreds of thousands and making vacant positions impossible to be filled? On the flip side, why would you bother joining a hipster language as a developer? Right now 35% of the jobs in my country are for C#, another 35% is for JAVA, 25% of them are for PHP or Python, the remaining 5% is for every other language but typically c/c++ for robotics. JavaScript/typescript is involved in quite a lot of the positions, but almost no one is doing a JS backend. There isn’t a single OCalm or Rust position available in my entire country. I’m not sure there has ever been a Rust related position. Management doesn’t care about technical reasons, and it never will. Developers tend to go where the jobs are, even if they have hobby projects somewhere else. Maybe Rust will somehow manage to break through, Python did after all. But I think Python had a huge amount of help from being the replacement for JAVA at many universities. I don’t see that happening for Rust.
- ax2 8y agoss
- ax2 8y agox
- ax2 8y agotest
- ax2 8y ago"><script>alert(0)</script>
- laughingman2 8y agoAny extensions for emacs?
- grandinj 8y agoIs it just me or did no one else parse this as a joke project because pyrite == fools gold?
- jefurii 8y agoProject logo suggests they're aware of it.
- mlevental 8y agois there a way to get any of these python typecheckers to automatically annotate my code?
- igouy 8y agoYes -- see pytype.