Title: Type Hints Syntax
Type: enhancement Stage:
Components: Versions:
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: YoSTEALTH
Priority: normal Keywords:

Created on 2016-12-03 20:48 by YoSTEALTH, last changed 2016-12-04 01:40 by YoSTEALTH. This issue is now closed.

Messages (2)
msg282304 - (view) Author: (YoSTEALTH) * Date: 2016-12-03 20:48
Type Hints Syntax

Goal: Is to make it easy to read function/methods arguments, yet keep the new and cool Type Hints.

For example this is a code from one of my function. Its getting to that point of what the heck is going on here?

def find_replace(string: str, find: (str, dict, list, tuple, set), replace: (str, list, tuple, set)='') -> str:

I know it can be rewritten as:

T = (str, dict, list, tuple, set)
def find_replace(string: str, find: T, replace: T='') -> str:

But when you start using variable to represent another variables type... maybe we are losing the plot here!

What if we could have both? Readability and type reference, what if it could be written as:

def find_replace(string, find, replace):
    targ str, *(str, dict, list, tuple, set) -> str
    # code here ...

targ = type argument (like *args and **kwargs)

Calling a "targ" like we call "global" but to represent types.

Simple Examples:

def Redirect(url='', code=301):
    targ (str, int) -> None

Just think about it...
msg282313 - (view) Author: (YoSTEALTH) * Date: 2016-12-04 01:40
I was told to post this in python-ideas and also i totally missed the most important part (type aliases) in my example (rushed it)
Date User Action Args
2016-12-04 01:40:01YoSTEALTHsetstatus: open -> closed

messages: + msg282313
2016-12-03 20:48:45YoSTEALTHcreate