The typing.AnyStr documentation: https://docs.python.org/3/library/typing.html#typing.AnyStr It gives some examples using u-strings (u'foo') but doesn't make explicit some subtleties about behaviour with Python 2. Specifically, with Python 2 all the given examples work, and even this works: concat("foo", u"bar") Which seems contrary to the goal of AnyStr being "used for functions that may accept any kind of string without allowing different kinds of strings to mix". I think the documentation should call out that for Python 2, AnyStr doesn't distinguish between str & unicode, and mention that in python 2, b'str' is equivalent to 'str' (I know this is mentioned elsewhere, but it seems useful to repeat it here).
Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) *
Date: 2016-12-18 01:11
The ``typing`` module doesn't exist in Python 2.7. All code samples provided in the docs *work* since no type-checking is performed by Python. That is, no enforcing of the types provided is made, that's for 3rd party packages to supply.
Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) *
Date: 2016-12-18 01:33
Unless of course you mean pip installing typing for Py2 and then using ``# type`` comments to provide the types. Even in that case, I don't really think the documentation for Python 3.5 should be mentioning types in 2.7, that'd get confusing.
I agree that it would just be confusing if the Python 3 docs were to explain Python 2 specific things. Maybe this should be explained in the mypy docs (or maybe it's really a mypy bug). Can you open an issue there?
History
Date
User
Action
Args
2022-04-11 14:58:40
admin
set
github: 73188
2017-01-07 22:00:24
gvanrossum
set
status: open -> closednosy: + gvanrossummessages: + resolution: wont fix