[Python-ideas] C#-style "as" casting syntactic sugar for type hints

2023-03-23 Thread Will Bradley
This is some real code I wrote the other day: payload = { "birthDate": str(date.strftime('%m/%d/%Y')), ... } Due to the fact that date.strftime returns Any type, for my type hinting and autocomplete to work I either need to pass it to the str function or typing.cast(str, date). It would be nice if

[Python-ideas] Re: C#-style "as" casting syntactic sugar for type hints

2023-03-23 Thread Damian Shaw
But doesn't date.strftime returns str not Any: https://github.com/python/typeshed/blob/main/stdlib/datetime.pyi#L75 ? Damian On Thu, Mar 23, 2023 at 10:00 PM Will Bradley wrote: > This is some real code I wrote the other day: > payload = { > "birthDate": str(date.strftime('%m/%d/%Y')), > ... >

[Python-ideas] Re: C#-style "as" casting syntactic sugar for type hints

2023-03-23 Thread Chris Angelico
On Fri, 24 Mar 2023 at 13:02, Will Bradley wrote: > It would be nice if I could just write "birthDate": > date.strftime(r'%m/%d/%Y') as str, like in C#. I'm sure it would - for you. Unfortunately it would most definitely NOT be nice to write: with something as str: and then be unsure whether y