[Python-ideas] Type hints for text/binary data in Python 2+3 code
Andrey Vlasovskikh
andrey.vlasovskikh at gmail.com
Tue Mar 22 17:51:49 EDT 2016
> 2016-03-22, в 20:58, Guido van Rossum <guido at python.org> написал(а):
>
> One thing I can do without committing to too much is to add a Text
> type to typing.py. It would have no (defined) behavior but it could be
> imported and used in annotations. Then mypy and other checkers could
> start using it and we could even experiment with different proposals
> without having to make more changes to typing.py (which we've found
> are hard to push out, because it's in the 3.5 stdlib -- it's
> provisional so we can change it, but we can't easily change what's
> already in 3.5.0 or 3.5.1).
>
> Should it be possible to subclass Text, and what should it mean?
>
> Or perhaps at runtime (i.e. in typing.py) Text would just be an alias
> for str in Python 3 and an alias for unicode in Python 2? That's
> easiest.
Defining typing.Text as an alias to str in Python 3 and unicode for Python 2 (the way six.text_type is defined) looks like a good idea.
I would recommend to prohibit subclassing typing.Text at the moment in the module docs and in PEP 484. We can always allow subclassing it later, but right now it's not clear wether it's safe or not given the fact that it's defined conditionally for 2/3.
--
Andrey Vlasovskikh
Web: http://pirx.ru/
More information about the Python-ideas
mailing list