3 ms·
If your code doesn't need to be py 2/3 compatible it's fine to annotate using str. But if you do, typing.Text and bytes is better.
by yegle 7y ago
If your code doesn't need to be py 2/3 compatible it's fine to annotate using str. But if you do, typing.Text and bytes is better.
- rcfox 7y agoGood to know, but I hope to never need this.
- quietbritishjim 7y agoAm I missing something? Annotations aren't supported by Python 2 so if you're using them then you never need to worry about Python 2/3 compatibility.
- joshuamorton 7y agoYes and no. Annotations in comments or in type stubs are supported in python2 (you can look at typeshed for typing.Text and conditional py2/3 stuff). There's also some other cases, but they're...unique.
- rcfox 7y agomypy supports comment-based annotations for Python 2. https://mypy.readthedocs.io/en/latest/python2.html https://mypy.readthedocs.io/en/latest/python2.html