Text
, on Python 2, includes bytes
? · Issue #418 · python/typing (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
typing.Text
, on Python 2, maps tounicode
.unicode
is automatically promoted toUnion[str, unicode]
, see special rules in typeshed pyi typeshed#270
The combination of these two rules means that an annotation Text
now includes bytes
, on Python 2.
And indeed, the below type-checks, with both pytype
and mypy --python-version=2.7
:
import typing
def f(x):
# (typing.Text) -> None
pass
f(b"foo")
This seems a bit odd to me. It also means that we don't have a cross-version way to express "unicode string". Should Text
not do the auto-promotion, so that it only stands for unicode
itself, on Python 2?