Python: Even a Feature That You Do Not Use Can Bite You
blog.petrzemek.net
Python: Even a Feature That You Do Not Use Can Bite You
1–10 of 48 posts
Re: Python: Even a Feature That You Do Not Use Can Bite You
#2Re: Python: Even a Feature That You Do Not Use Can Bite You
#3But I'll admit I got bit by exactly this recently, wrote up an "assignment" using a colon instead of an equal sign and it didn't do anything, but didn't fail either.
Somewhat frustratingly, pycharm didn't warn about it either. I should probably check their bug tracker to see if somebody already reported it.
Re: Python: Even a Feature That You Do Not Use Can Bite You
#4Re: Python: Even a Feature That You Do Not Use Can Bite You
#5Re: Python: Even a Feature That You Do Not Use Can Bite You
#6Any IDE or linter worth its salt would catch this for you.
Re: Python: Even a Feature That You Do Not Use Can Bite You
#7Re: Python: Even a Feature That You Do Not Use Can Bite You
#8In this case you hit the most benign sort of change: Code that was previously syntactically invalid is now syntactically valid but has silly semantics. There’s never going to be a way to avoid this with full generality, and your code never worked — type annotations just delayed your runtime error by one line.
When annotations were introduced in 3.4, there was no requirement they be used to annotate types instead of something else, so any valid Python expression is allowed syntactically. In 3.6 the use of annotations for anything other than types was provisionally deprecated, and in 3.7 is fully deprecated. In 3.8, non-type usage will be disallowed as a TypeError, and the only allowable non-type annotations will be strings, (which will be interpreted as bare identifiers for backward compatibility with pre-3.7 code that uses them as forward references). At this point your code will revert to raising an exception on exactly the same line it used to.