4 ms·
I gave up on using mypy as I was spending more time telling it to shut up than actually using it catch mistakes ahead of the time. That said using type annotat
by carlosf 5y ago
I gave up on using mypy as I was spending more time telling it to shut up than actually using it catch mistakes ahead of the time.
That said using type annotations made me realize I want to be fluent in a language with a strong static type system (huge productiveness booster imo), so I'm currently studying Typescript and nim.
- ZephyrBlu 5y agoI wish that you could use typed Python to speed up the execution of the program instead of them just being hints.
- m_mueller 5y agoafaik that was first planned for Python 4 and then dropped again :(
- ZephyrBlu 5y agoAny links on it being planned for Python 4? I didn't know they'd ever even considered it.
- m_mueller 5y agoI think that the mentions of that have been deleted from the relevant PEP since, but e.g. https://www.reddit.com/r/Python/comments/7zvyhx/pep_563_mentions_python_40_whats_going_on/ https://www.reddit.com/r/Python/comments/7zvyhx/pep_563_ment... is also asking about it.
- isoprophlex 5y agoNot exactly what you're talking about, but... For some types of functions, Numba's JIT offers some pretty nice speed ups. It can infer function types (or you supply them yourself) and compiles to optimized machine code
- chriswarbo 5y agoIt's tricky, since only the typed part can be sped up, and there will usually be lots of back-and-forth between typed and untyped code; which requires conversions and checks. For comparison, Racket has gradual typing which gives a speed boost when everything is typed, but can end up much slower if anything remains untyped, e.g. see figure 3 in http://www.ccis.northeastern.edu/home/types/publications/gradual-dead/pre-treatment.pdf http://www.ccis.northeastern.edu/home/types/publications/gra... Python would probably be even worse, since it's "more dynamic" than Racket; e.g. there are many hooks that can run arbitrary code (like dunder methods), and there's little encapsulation so values may get swapped out via monkey-patching at any time.
- Jiejeing 5y agoBut that is precisely what mypyc[0] is doing! It is part of mypy, and it compiles type-valid python files to cpython binary extensions, and takes advantage of a lot of shortcuts available to cut execution time. It is still a bit early to advocate for its use everywhere, and has it drawbacks (extensions compiled with mypyc will also typecheck the inputs and outputs of the module at runtime, which is great for improving code quality and validity of the annotations, but also means you may get TypeErrors in production if you hit a bad edge case). If there is no shortcut it will fallback to normal, slow, python performance, with some smallish benefits (e.g. vtables for attribute lookups, no parsing time, etc). [0] https://mypyc.readthedocs.io/ https://mypyc.readthedocs.io/
- goodpoint 5y agoNim feels very close to a typed Python.
- inbx0 5y agoHow do you think those two stack up against each other? Not trying to start language wars here, of course, I'm just interested because I find Nim one of those languages that I'd like to try but don't have a project/use case to try on.