Bottom Page

Poll: How much are you using type hinting?
Not at all
A little
A lot
[Show Results]
 
Note: This is a public poll, other users will be able to see what you voted for.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Type Hinting - who's using it?
#1
Who's using type hinting? What are your thoughts on it so far?
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#2
I wasn't aware it was there.
May (possible) use going forward can report back after I read up (later today)
Quote
#3
i guess i just got use to programming in python without it so i never use it.
Quote
#4
Have look into it and used it some times more to test it out.
Can use it there it make sense trough the concept of gradual typing.
Code without type hints will be ignored by the static type checker.
Therefore can start adding types to where it make sense and critical components,and continue as long as it adds value to you.

Bigger companies like eg Dropbox and Instagram use this heavily think now is almost mandatory for them.
Our journey to type checking 4 million lines of Python
Instagram has made MonkeyType to add type annotations to code where is not automatically.
So can take MonkeyType Shifty for test to see what it dos.
def double(number):
    return number * 2.5

print(double(4))
print(double(5.5))
Output:
10.0 13.75
So can take integer or float as input,and output will be float.
Using MonkeyType:
E:\div_code\read
λ monkeytype apply clean
After apply:
from typing import Union

def double(number: Union[float, int]) -> float:
    return number * 2.5

print(double(4))
print(double(5.5))

Conclusion i quote Python Type Checking (Guide) it's a well written Guide bye Geir Arne Hjelle a fellow countryman.
Geir Arne Hjelle Wrote:Conclusion

Type hinting in Python is a very useful feature that you can happily live without.
Type hints don’t make you capable of writing any code you can’t write without using type hints.
Instead, using type hints makes it easier for you to reason about code, find subtle bugs, and maintain a clean architecture.
Larz60+ likes this post
Quote
#5
I don't use it when doing quick prototyping, but I include it in all code at work, since the people I work with are used to languages like Scala and aren't used to dynamic typing. I agree that it doesn't let you write code you couldn't otherwise, but it really helps for things like code review where you don't have Pycharm or anything like that to help you figure out what types are. I've even caught would-be type errors in code review because people annotated their code correctly but forgot to run mypy to detect the contradiction.
metulburr likes this post
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#6
I can see where it would come in handy. When debugging, I often have print statements like print(f"{type(variable)}")
metulburr likes this post
Quote
#7
I don't use it.
My scripts usually aren't very big. And I prety much remember what I wrote.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#8
TypeHints helps me to recognize the API.

I don't use them in short scripts, but if the code is on different modules, I use them.
PyCharm will detect the use of TypeHints and will warn you, if you have chosen the wrong type.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)