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 <derivativedude...@gmail.com>
wrote:

> 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 I could just write "birthDate":
> date.strftime(r'%m/%d/%Y') as str, like in C#. It's shorter, (in my
> opinion) more readable, and avoids having to unnecessarily call
> a constructor or import typing.cast.
>
> It's important to note that this would be syntactic sugar for typing.cast—
> it wouldn't call any constructor or affect program state, just increase the
> power of the type hinting system.
>
> Will Bradley
> _______________________________________________
> 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/ZP6UHIHBOIZLO63QJPYTUSFXQBEKJVV4/
> 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/D4KWKVWF3HQQHHCAKF3OFNOQN7OLO4G7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to