Issue 33133: Don't return implicit optional types by get_type_hints (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/77314

classification

Title: Don't return implicit optional types by get_type_hints
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7

process

Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, levkivskyi
Priority: normal Keywords:

Created on 2018-03-24 18:16 by levkivskyi, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg314378 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2018-03-24 18:16
Currently this code def f(x: int = None): pass get_type_hints(f) returns {'x': Optional[int]}. I propose to abandon this behaviour. Although there is not yet a definitive decision about this aspect of PEP 484, see https://github.com/python/typing/issues/275, I think at least at runtime we should not do this.
msg314395 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2018-03-25 05:39
I'm not sure we should change this ahead of a definitive decision. When you use mypy with the option that forbids it, your program will be invalid, and it doesn't really matter what we do at runtime; but that option is not the default yet, and without that option, mypy treats the type as Optional[int].
msg314401 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2018-03-25 09:21
OK, let us then keep this issue as a remainder that we need to update the runtime behaviour when the static one changes.
History
Date User Action Args
2022-04-11 14:58:59 admin set github: 77314
2018-03-25 09:21:10 levkivskyi set messages: +
2018-03-25 05:39:44 gvanrossum set messages: +
2018-03-24 18:16:02 levkivskyi create