4 ms·
How is it backwards compatible? Was there syntax added to the language in preparation?
by jsmeaton 11y ago
How is it backwards compatible? Was there syntax added to the language in preparation?
- ghshephard 11y agoI have no idea how they managed to find something that didn't throw a syntax error, yet looked reasonable. Perhaps someone who followed the process will chime in.
- deleted 11y ago[deleted]
- koenigdavidmj 11y agohttps://www.python.org/dev/peps/pep-3107/ https://www.python.org/dev/peps/pep-3107/ They are just arbitrary expressions (though in Python, type names like 'int' or 'str' are themselves objects). They don't do anything by default but are accessible as fields of the function object.
- Walkman 11y agoIt was in there for a long time, just nobody used it.
- kqr 11y agoCorrect. Annotations were added in 3.0 with no encouragement to use them for anything in particular, so they could observe what the community would use them for. They were just put in a dictionary attached to the function, and by inspection you could access them and do whatever the heck you wanted with them. A lot of third-party libraries cropped up that used them to type-check stuff. Type-checking was a popular enough usage for them it's official now, to help gather people under the same libraries and terminology. You can still use the annotations for other things, of course – the dictionary is still attached to the function and can be inspected as before – but if nothing else is specified, we can now assume they are type declarations.