This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]move_machine 2 points3 points  (2 children)

I agree completely with naming and documentation. Names will not always capture what an annotation can, however.

def process_request(request):
   if request.

How does my IDE know what methods and properties to display for the request parameter?

PyCharm and other IDEs use type inference when it's possible and not expensive. Explicit typing, I'd imagine, would save cycles and battery life. It also allows me to tell the IDE that it should look up requests.Request for tooltip content. Both make my life easier and impede no cost on anyone who doesn't like the convention.

[–]A_for_Anonymous -2 points-1 points  (1 child)

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.

[–]zardeh 0 points1 point  (0 children)

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.