4 ms·
While it’s not common (from the source code I’ve reviewed over the years), some people make a new type with a name and use that in the definition: ``` from ty
by LordKeren 2y ago
While it’s not common (from the source code I’ve reviewed over the years), some people make a new type with a name and use that in the definition:
```
from typing import NewType
# Create a new type for some_prime
SomePrime = NewType('SomePrime', int)
def process_prime(value: SomePrime) -> int:
return value
```
However, this isn’t nearly as common as simply using a more descriptive argument name like “prime_number : int”
One of the big advantages to type hinting in Python is that it feeds the IDE a lot of information to increase auto-complete functionality, so you want to avoid things like p:”prime number”
- pansa2 2y ago> One of the big advantages to type hinting in Python is that it feeds the IDE a lot of information to increase auto-complete functionality Yeah, until this discussion I thought the main benefit of type hints was earlier detection of bugs via static checking. Now though, I'm getting the impression that the bigger benefit is enabling IDE features such as autocomplete. That helps me understand better why I haven't found type hints as useful as others seem to - I don't use an IDE. My use of Python is limited to small scripts which I write in a simple text editor.
- LordKeren 2y agoThere’s a fair argument to make that better IDE autocomplete does prevent many type-related issues even before a static type checker is run