I find myself using exactly that "picture of the data" approach informally
for code I don't plan on formally type checking (but want to show intent).

E.g.

def myfun(data: {str: [CustomType]}) -> [(int, OtherType)]: ...

Maybe it's a bad habit, but it feels easier to parse visually than the real
`typing.py` stuff.


On Wed, Oct 13, 2021, 4:35 PM Abdulla Al Kathiri <
alkathiri.abdu...@gmail.com> wrote:

> Hello,
>
> Today I found myself write a function that returns a tuple of list of list
> of strings (tuple[list[list[str]], list[list[str]]]). Wouldn’t it easier to
> read to write it like the following:
> ([[str]], [[str]])?
> Similarly for TypedDict, replace the following..
>
> class Movie(TypedDict):
>     name: str
>     year: int
>
> with
> {‘name’: str, ‘year’: int}
> dict[str, int] will be {str: int}
> set[int] will be {int}.
> This is similar to the new proposed Callable alternative (i.e., (int,
> float) -> float) since it mimics the structure of a function.
>
> Also, Annotated[float, “seconds”] can be replaced with something like
> float #seconds indicating whatever comes after the hashtag is just extra
> information similar to a normal comment in the code.
> Imagine you could replace the following
> def func(d: dict[Annotated[str, “product label”], Annotated[list[float],
> “prices from 2000 to 2015”]])…
> With
> def func(d: {str # product label: [float] # prices from 2000 to 2015})…
> Abdulla
> Sent from my iPhone
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/D6LHXDXPN6K27KV6MZBLG66ZSGCNDRG7/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HYBIYHKE4ZAKTV33VB4AE37MG576KYH5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to