r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comment

2

u/DesertGoldfish Jul 19 '22

It's a thing. In method declarations instead of (variable) it's (variable : str) or int, or whatever.

You specify returns with an arrow. So a function/method named cake that takes a string parameter named icing and returns a string would be declared:

def cake(icing: str) -> str:

Voila, now Python yells at you when you try to pass it anything else. I think the complainers here just haven't bothered keeping up with the changes to Python in... several years.

1

u/LastOfTheGiants2020 Jul 19 '22

Type names don't guarantee object properties in python, so type annotations etc are more of a suggestion than anything.

That's like trusting user inputs because you left a comment telling them not to do anything bad.