-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
passing unicode to some of the stdlib functions produces incorrect mypy error in python 2.7 #1411
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
Comments
As mentioned on gitter, the taker of this should also look at whether this method takes unicode |
In my code, I pass |
Part of python#1411 urlunsplit() and similar functions accept either unicode or str in all places. Their actual return type is unicode if any of the arguments is unicode and nonempty, which the type system can't exactly express. I left the return type as str because str is implicitly promoted to unicode, so using the return type in a place that accepts unicode should work. unquote, parse_qs, and parse_qsl return unicode if you pass them unicode, so AnyStr is appropriate in their stubs.
Part of python#1411 Also remove some explicit parameter defaults.
I'm about to submit PRs to fix two of the issues you mentioned. I'm not sure your third issue (using unicode keys for a **kwargs dict) can be fixed in typeshed. The hack proposed in python/mypy#3619 will probably fix it though. |
Part of python#1411 Also remove some explicit parameter defaults.
See also python/mypy#1954. |
* urlparse: allow unicode arguments in more places Part of #1411 urlunsplit() and similar functions accept either unicode or str in all places. Their actual return type is unicode if any of the arguments is unicode and nonempty, which the type system can't exactly express. I left the return type as str because str is implicitly promoted to unicode, so using the return type in a place that accepts unicode should work. unquote, parse_qs, and parse_qsl return unicode if you pass them unicode, so AnyStr is appropriate in their stubs. * fix type for urldefrag The return type was wrong; this function returns a 2-tuple. The second member of the tuple is always a `str` if the argument type does not contain '#', and otherwise matches the type of the argument.
Part of #1411 Also remove some explicit parameter defaults.
Both of the functions mentioned are fixed. |
same issue for:
|
This issue highlights few incorrect stubs in Python 2
stdlib
stub files. Most of these are related to passingunicode
string tostdlib
functions which work correctly at runtime, butmypy
shows unsupported type. (because stub files have mentionedstr
as the only allowed type)List of the errors
The docs mention that for
urlunsplit
function,The parts argument can be any five-item iterable.
relevant docs link: https://docs.python.org/2/library/urlparse.html#urlparse.urlunsplit
current stubs for the function: https://github.com/python/typeshed/blob/master/stdlib/2/urlparse.pyi#L58
There might be other functions in the
urlparse
which might have similar bug.passing unicode string in
open()
builtin and askey
to a dict.test.py
output
Updated issue to include other found errors
The text was updated successfully, but these errors were encountered: