Skip to content

Issues with type hints for urllib.parse.urldefrag #2477

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
3 tasks done
mr-c opened this issue Sep 25, 2018 · 2 comments · Fixed by #8204
Closed
3 tasks done

Issues with type hints for urllib.parse.urldefrag #2477

mr-c opened this issue Sep 25, 2018 · 2 comments · Fixed by #8204
Labels
stubs: false negative Type checkers do not report an error, but should stubs: false positive Type checkers report false errors

Comments

@mr-c
Copy link
Contributor

mr-c commented Sep 25, 2018

  • PY3: reveal_type(urldefrag(...)[1]) should retain the type of the input instead of Any
  • PY2: reveal_type(urldefrag(...)[1]) should not be fixed as str; should be unicode when a unicode input is provided
  • PY2: type for urldefrag should be updated to allow unicode input
from six.moves import urllib
from typing_extensions import TYPE_CHECKING

if not TYPE_CHECKING:
    def reveal_type(ignored):
        pass

_, frg = urllib.parse.urldefrag("https://github.com/python/typeshed/#typeshed")
print(type(frg))
reveal_type(frg)

_, frg2 = urllib.parse.urldefrag(u"https://github.com/python/typeshed/#typeshed")
print(type(frg2))
reveal_type(frg2)

_, frg3 = urllib.parse.urldefrag(b"https://github.com/python/typeshed/#typeshed")
print(type(frg3))
reveal_type(frg3)
$ mypy  typing-defrag-test.py                                                                                          
typing-defrag-test.py:11: error: Revealed type is 'Any'
typing-defrag-test.py:15: error: Revealed type is 'Any'
typing-defrag-test.py:19: error: Revealed type is 'Any'

$ mypy --py2  typing-defrag-test.py                                                                                    
typing-defrag-test.py:11: error: Revealed type is 'builtins.str'
typing-defrag-test.py:13: error: Argument 1 to "urldefrag" has incompatible type "unicode"; expected "str"
typing-defrag-test.py:15: error: Revealed type is 'builtins.str'
typing-defrag-test.py:19: error: Revealed type is 'builtins.str'
$ python3 typing-defrag-test.py                                                                                         
<class 'str'>
<class 'str'>
<class 'bytes'>

$ python2 typing-defrag-test.py                                                                                        
<type 'str'>
<type 'unicode'>
<type 'str'>
$ mypy --version
mypy 0.630
$ python -V
Python 2.7.15+
$ python3 -V
Python 3.6.6+
@srittau srittau added stubs: false positive Type checkers report false errors size-medium stubs: false negative Type checkers do not report an error, but should labels Nov 29, 2018
@mr-c
Copy link
Contributor Author

mr-c commented Jun 21, 2019

This is still occurring :-P

@AlexWaygood AlexWaygood changed the title type hints for urldefrag inconsistencies and shortcomings Issues with type hints for urllib.parse.urldefrag Jun 14, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 14, 2022

I've ticked off the Python-2-specific items, since we'll soon be dropping support for Python 2 entirely ( #7367). The Python-3 issue still reproduces, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false negative Type checkers do not report an error, but should stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants