Skip to content

Add typing.Text? #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthiaskramm opened this issue Apr 18, 2016 · 7 comments
Closed

Add typing.Text? #204

matthiaskramm opened this issue Apr 18, 2016 · 7 comments

Comments

@matthiaskramm
Copy link
Contributor

See python/mypy#1141 and https://groups.google.com/forum/#!topic/python-ideas/gA1gdj3RZ5g

Having typing.Text as an alias for (on Python 2) Union[str, unicode] and for (on Python 3) Union[bytes, str] would simplify some stubs in typeshed. (And allow typeshed stubs to be shared between Python 2 and 3)

However, there are concerns that people would use typing.Text in *.py, not just *.pyi, thus weakening the type-checking static analysis tools can do. (And the distinction between unicode and str in Python 2 programs is critical when porting to Python 3)

@gvanrossum
Copy link
Member

gvanrossum commented Apr 18, 2016

I don't think any of the proposals on the table includes Text being Union[bytes, str] in Python 3. The two types are intentionally different, and AFAIK all proposals have Text = str in Python 3 (TBH if I had to do it over I would have renamed str to text in Python 3, ten years ago). In Python 2 I currently have Text = str [SEE EDIT] but arguably the better type there would be basestring, once I add the proper methods to it (I have a PR out but it's a big refactor and I'm worried it would break something: python/typeshed#138).

EDIT in Python 2 Text = unicode currently.

@vlasovskikh
Copy link
Member

typing.Text has been already added with another meaning, see 6da9fc2. See #19.

@matthiaskramm
Copy link
Contributor Author

Interesting. In that case, I believe typeshed should start using Union[Text, bytes] in a few places, particularly in 2to3/.

@gvanrossum
Copy link
Member

gvanrossum commented Apr 18, 2016 via email

@matthiaskramm
Copy link
Contributor Author

AnyStr is a type parameter, which doesn't work in all cases. (Typical example is a function with two arguments, and they both can either be str or unicode, but don't have to have the same type)

@gvanrossum
Copy link
Member

OK, go ahead and make the changes you think are necessary, or send them to me as PRs. This should be pretty uncontroversial.

@gvanrossum
Copy link
Member

typing.Text now exists everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants