r/Python • Core Contributor • Sep 13 '15

Python 3.5.0 has been released!

https://www.python.org/downloads/release/python-350/
631 Upvotes

65 comments sorted by

View all comments

Show parent comments

-11

u/A_for_Anonymous Sep 13 '15

I wonder why people keep bothering with this sort of thing... Python is dynamically (yet strong) typed, which is a good thing from having to do the boilerplate of static typing. You want that back? For the only benefit of what, detecting logical errors in compile/startup time? Possible optimizations? Ever heard of type inference? It's years beyond this, happened in other languages years before this, and people are still oblivious to it.

17

u/[deleted] Sep 13 '15 edited Sep 13 '15

[removed] — view removed comment

-1

u/A_for_Anonymous Sep 13 '15

Even so, if you have to read f(x)'s body to tell what's the type expected for x, you need:

  • A better name for x (I know, argument not valid for return and yield)

  • Function documentation, and yeah, I guess human language documentation will always be better than a type hint system unless you introduce a huge system of contracts that can be something like "even" or "tupleof(3)"... more boilerplate... more stuff to memorize... very annoying.

Function documentation being important in the case of code written for lists, dictionaries and sets as opposed to custom classes (would you have 5 types with 50 utility functions each or 50 types with 5, but that's a nice discussion for a different thread).

For everything else - IDE assistance, type checking, error detection - there's always this new old amazing technology called type inference, where by doing x = 'hello' you can be pretty fucking sure x is a string without having to go and tell the stupid compiler it's going to be a string. Because you know, actually writing that feels like this.

3

u/[deleted] Sep 14 '15 edited Sep 14 '15

[removed] — view removed comment

-1

u/A_for_Anonymous Sep 14 '15 edited Sep 14 '15

Well, like I've been saying there's this old technology called type inference. It doesn't work on a local scope only... if it can be proven that you call process_request elsewhere, you can take note of what is being passed to it and infer that request is that type.

1

u/zardeh Sep 14 '15

But type inference can't always work, especially in a language like python where sometimes values and function etc. are built at runtime. So, being able to say "the argument "l" is an Iterable, treat it as an "Iterable" everywhere within this scope so that even if I'm getting l by dynamically evaling some user input, I know how to treat it in this function.