Re:Why type hinting sucks (/r/Python)
by jerpint on Saturday February 11, 2023 @07:56AM
(#34751941)
Typehints are a great way to document code. If the type hints get too complex they can be cumbersome though. For example passing an int or None if the value doesn’ exist
[ Parent
| on HN ]
Passing an int and, if the value doesn't exist, a None can be expressed quite neatly like this: "Optional[int]"
`int | None` is often prefered in the newest versions.
Re:Why type hinting sucks (/r/Python)
by codethief on Saturday February 11, 2023 @09:36AM
(#34752630)
I must have missed this. Union types using | are possible now?
Yes, saves the import and looks cleaner IMHO https://www.blog.pythonlibrary.org/2021/09/11/python-3-10-si...