5 ms·
Actually I really wish there was an option similar to typescript for Python. There are promising things.. but the annotations, for example, are just not there y
by make3 9y ago
Actually I really wish there was an option similar to typescript for Python. There are promising things.. but the annotations, for example, are just not there yet
- dom0 9y agoAnnotations at least help the IDE dig through the mess faster. That's ... something. I guess.
- ATsch 9y agowhat would you say are the limitations of Python type annotations? From the pycon demos I've seen it seems pretty functional and complete.
- deathanatos 9y ago* pylint / pep8 doesn't parse comment-based annotations, and thus flags imports that are in use as "unused" * numbers.Real / Union[float,int] do not work correctly; I basically can't figure a way to annotate a function that takes an int/float/decimal/etc. (mypy doesn't think "int" is a valid "Real", and it doesn't think you can add two Union[float,int] objects.) (mypy has nonetheless been very helpful, and overall I would recommend it.)
- slaymaker1907 9y agoYou don't need comment based annotations since there are real annotations since python 3.5
- deathanatos 9y agoWhile true, my codebase regrettably needs to run in Python 2.7.
- make3 9y agoI can't tell if you're neglecting the fact that most production Python is Python 2 on purpose or not
- yorwba 9y ago> I basically can't figure a way to annotate a function that takes an int/float/decimal/etc. It seems like you should be able to just annotate it with float? ... when an argument is annotated as having type float , an argument of type int is acceptable ... https://www.python.org/dev/peps/pep-0484/#the-numeric-tower https://www.python.org/dev/peps/pep-0484/#the-numeric-tower
- deathanatos 9y agoHmm. I wasn't aware of that; still, it seems to not work for Decimal objects.
- deleted 9y ago[deleted]
- slaymaker1907 9y agoI mostly found the type annotations to be sufficient, though the tooling look leaves something to be desired.
- Rotareti 9y agoI'm very satisfied with the new typing [0][1] module. It's part of the standard library since Python 3.5 and it provides type annotations similar to those of Typescript. It's still missing some features (IMO), but it's also under active development, so I guess more useful features will come. from typing import List Vector = List[float] def scale(scalar: float, vector: Vector) -> Vector: return [scalar * num for num in vector] def greeting(name: str) -> str: return 'Hello ' + name [0] https://github.com/python/typing https://github.com/python/typing [1] https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html