python-discord / meta

Issue tracker for suggestions and other questions relating to our community
https://pythondiscord.com
31 stars 5 forks source link

Add "What's a typehint" tag #154

Closed jonathan-d-zhang closed 2 years ago

jonathan-d-zhang commented 2 years ago

Lots of people wonder what at typehint is, so this tag addresses that.

Draftish: A typehint indicates to users of a function what type it expects to be passed, as well as indicating what type the return value of the function should be.

def add(a: int, b: int) -> int:
    return a + b

Note that this has no actual effect on what is passed, for example, this is valid code

add("hey", ["yo", 2])
bsoyka commented 2 years ago

I'd go with "type hint" and "type hinting" rather than "typehint" and "typehinting" for consistency with the Python docs, but otherwise I love the idea!

doublevcodes commented 2 years ago

I'd like to point out that it doesn't have to be a function,

a: int = 5

is perfectly valid. Perhaps something more like "A type hint indicates the type of a variable. It can also be used to show what type a function returns"

vcokltfre commented 2 years ago

Note that this has no actual effect on what is passed, for example, this is valid code

add("hey", ["yo", 2])

This is not valid code, it doesn't break because of the type hints but it does break.

TizzySaurus commented 2 years ago

Note that this has no actual effect on what is passed, for example, this is valid code

add("hey", ["yo", 2])

This is not valid code, it doesn't break because of the type hints but it does break.

Yeah, the reason it breaks is because of the code within the function (concatenating a string with a list) not the type hints (which I think is what they meant). This should be clarified though.

@SavagePastaMan were you planning on implementing this yourself? If so, I'll go ahead and assign you.

jonathan-d-zhang commented 2 years ago

Note that this has no actual effect on what is passed, for example, this is valid code

add("hey", ["yo", 2])

This is not valid code, it doesn't break because of the type hints but it does break.

Yeah, the reason it breaks is because of the code within the function (concatenating a string with a list) not the type hints (which I think is what they meant). This should be clarified though.

@SavagePastaMan were you planning on implementing this yourself? If so, I'll go ahead and assign you.

yeah, i can implement it. also, i can just change it to add(["Hey"], ["yo", 2])

TizzySaurus commented 2 years ago

yeah, i can implement it. also, i can just change it to add(["Hey"], ["yo", 2])

Have assigned you :+1:

I think using two strings would be better personally (something like add("Hello", "World")), since this is going to be targeted towards beginners who may not realise concatenation of lists is a thing.

jonathan-d-zhang commented 2 years ago

i'll write up a short draft and we can bikeshed about stuff. would i put that in a PR to the bot repo?

TizzySaurus commented 2 years ago

i'll write up a short draft and we can bikeshed about stuff. would i put that in a PR to the bot repo?

Yeah, I'd say so. Just make sure to link this issue (Closes python-discord/meta#154.)

If you @ me in the PR (and in #dev-contrib) I'll review it when I'm free :+1: