3 ms·
As of Python 3.10, you can use `T | U` instead of Union. Starting from 3.8 (I think), you can also directly use dict[T, U] and list[T] rather than having to im
by saila 4y ago
As of Python 3.10, you can use `T | U` instead of Union.
Starting from 3.8 (I think), you can also directly use dict[T, U] and list[T] rather than having to import Dict and List.
- wheelerof4te 4y agoI would rather see work done on something more useful than new syntax for typing.
- nine_zeros 4y agoI am amazed at how much time some devs will waste on trying to figure out type annotations, at the expense of actual work time.
- saila 4y agoLearning any new syntax, feature, etc takes time. IME learning type annotations can pay major dividends. For example, I wrote some type-annotated code the other day and mypy pointed out a couple places where I was passing the wrong type, which saved me from having to fix those bugs later, thus saving time for "actual work."
- nine_zeros 4y agoThere is a recurring cost to complex type annotations and that is that every single developer working on that repo (could be thousands) has to unravel the complex types, their aliases and the instance objects to modify any code. This as opposed to a legitimate type system where complex types are classes themselves which don't need unraveling. There is no need to alias a type and there is no need to maintain separate complexities for the object and the type.
- saila 4y agoI agree that complexity could be an issue with Python's typing, which has some flaws, although it's been improving. Type aliases are okay if they're not overly complex, having used them in Python and other languages to good effect, e.g. to avoid duplication or for clarity. I'd suggest using type annotations where it's not overly onerous--which is probably most places--to get the benefits without much effort but perhaps avoid them or use simplified types where it's too complex. I also agree that there are places where typing is unnecessary and doesn't add much value, such as in certain scripts. Like many things in programming, it's all about finding the right trade-offs.