This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2016-12-03 20:48 by YoSTEALTH, last changed 2022-04-11 14:58 by admin. 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:
    pass

I know it can be rewritten as:

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

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)
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73047
2016-12-04 01:40:01YoSTEALTHsetstatus: open -> closed

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