4 ms·
How is python's added typing compared to TypeScript? Is it expressive enough to completely supplant traditional Python or is it just something you add in someti
by Waterluvian 7y ago
How is python's added typing compared to TypeScript? Is it expressive enough to completely supplant traditional Python or is it just something you add in sometimes to help out a little?
- justwalt 7y agoIf I'm not mistaken, all of the types are akin to comments: completely ignored by the interpreter.
- jdm2212 7y agoSo there's the same situation as with TS where you can't do runtime reflection to get type annotations? That seems frustrating. The one really rough edge I've seen in TS is type guards. Not the end of the world, obviously, but still kinda gross coming from Java.
- j88439h84 7y agoYou can get annotations for functions and classes with `typing.get_type_hints()`.
- michael_j_ward 7y agoYou can get type annotations at runtime. And you can use this for validation with something you roll yourself or with 3rd party packages. I've used pydantic [1] before and found it quite nice. [1] https://pydantic-docs.helpmanual.io https://pydantic-docs.helpmanual.io
- deleted 7y ago[deleted]
- j88439h84 7y agoPretty much all of my Python is typed with attrs and mypy. It's great.
- ledauphin 7y agoit lacks some nice features like built-in structural subtyping (which is basically the default in TypeScript) - see my other post. A few things are a little clunkier because they're being added to an existing language rather than the language, and having to import things just to get Optional and generics is kind of ugly. But functionally, it's pretty much all there.