[Python-ideas] Enabling / disabling optional type hinting

Gregory P. Smith greg at krypto.org
Sat Mar 23 15:44:29 EDT 2019


On Sat, Mar 23, 2019 at 11:00 AM Stefan Krah <skrah at bytereef.org> wrote:

> On Sat, Mar 23, 2019 at 10:37:43AM -0700, Gregory P. Smith wrote:
> > A useless statement like that isn't likely to be typed.  I've never seen
> > anyone do that.
>
> Unlikely yes, but ideally type annotations should not alter program
> behavior:
>
> >>> d = {}
> >>> try: d["x"]
> ... except KeyError: print("KeyError")
> ...
> KeyError
> >>>
> >>> d = {}
> >>> try: d["x"] : int
> ... except KeyError: print("KeyError")
> ...
>

Unfortunately that isn't what PEP 526 said:
https://www.python.org/dev/peps/pep-0526/#annotating-expressions

-gps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190323/ace11010/attachment-0001.html>


More information about the Python-ideas mailing list