[issue41488] Unusable type hint should not be silently ignored

Andre Roberge report at bugs.python.org
Wed Aug 5 10:25:11 EDT 2020


New submission from Andre Roberge <andre.roberge at gmail.com>:

The following code is currently consistent with the type hint syntax but contains a line that is completely ignored.

   >>> d = {}
   >>> d['a']: int
   >>> d
   {}
   >>> __annotations__
   {}
    >>> '__annotations__' in dir(d)
   False

I believe that type hints that cannot be either attached to an object nor added to any other __annotations__ dict should either generate a SyntaxError or, at the very least, result in a warning.

----------
messages: 374884
nosy: aroberge
priority: normal
severity: normal
status: open
title: Unusable type hint should not be silently ignored
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41488>
_______________________________________


More information about the Python-bugs-list mailing list