This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unusable type hint should not be silently ignored
Type: behavior Stage: resolved
Components: Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: aroberge, gvanrossum, levkivskyi
Priority: normal Keywords:

Created on 2020-08-05 14:25 by aroberge, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg374884 - (view) Author: Andre Roberge (aroberge) * Date: 2020-08-05 14:25
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.
msg374889 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-08-05 15:03
No, that is up to the static type checker. With PEP 563 nearing completion in Python 3.10 we will in fact be ignoring all annotations silently.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85660
2020-08-05 15:03:27gvanrossumsetstatus: open -> closed
resolution: not a bug
messages: + msg374889

stage: resolved
2020-08-05 14:53:46xtreaksetnosy: + gvanrossum, levkivskyi
2020-08-05 14:25:10arobergecreate