|
|
Subscribe / Log in / New account

Type hinting for Python

Type hinting for Python

Posted Jan 14, 2015 22:02 UTC (Wed) by njs (subscriber, #40338)
In reply to: Type hinting for Python by rsidd
Parent article: Type hinting for Python

There was some discussion of this in the python-dev thread, including the Cython developers weighing in.

Short version: the Python type system is pretty much useless for speeding anything up, b/c just knowing that some variable IS-A 'dict' object tells you literally nothing about how it acts -- it's legal to subclass 'dict' and override all methods. (It's a terrible idea to do this, Liskov blah blah, but the language doesn't forbid it.) The types Cython adds are all assertions about C memory layout and C level semantics, which is a totally different and inconsistent system from Python types. And Python isn't going to grow a whole new type system any time soon, so speedups and Cython compatibility are pretty much off the table here.

This type-hinting stuff IIUC has a totally different and orthogonal goal, which is to let developers quickly check assertions like "I caught all the old places that assumed this variable was a tuple instead of the class I just upgraded it to" (without having to write 100% coverage test-suites), or IDEs to provide better suggestions/autocompletion. Stuff like that. Kinda disappointing if you were hoping for the other kind of type assertions, but useful.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds