Text, on Python 2, includes bytes? · Issue #418 · python/typing (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@matthiaskramm

Description

@matthiaskramm

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?