Skip to content
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

urlretrieve can accept filename: pathlib.Path for Python>=3.6 #2194

Merged
merged 3 commits into from Jun 5, 2018
Merged

urlretrieve can accept filename: pathlib.Path for Python>=3.6 #2194

merged 3 commits into from Jun 5, 2018

Conversation

@scivision
Copy link
Contributor

@scivision scivision commented Jun 4, 2018

For Python >= 3.6, urllib.request.urlretrieve() can accept argument filename= str or pathlib.Path, this Pull Request is intended to allow type checkers to acknowledge this fact.

This was prompted by MyPy 0.600 giving error:

error: Argument 2 to "urlretrieve" has incompatible type "Path"; expected "Optional[str]"

when passing a pathlib.Path filename.

@@ -188,7 +189,7 @@ class HTTPErrorProcessor(BaseHandler):
def https_response(self) -> _UrlopenRet: ...


def urlretrieve(url: str, filename: Optional[str] = ...,
def urlretrieve(url: str, filename: Optional[Union[str, Path]] = ...,

This comment has been minimized.

@JelleZijlstra

JelleZijlstra Jun 4, 2018
Member

Can you add a version check if sys.version_info >= (3, 6): and allow os.PathLike[str] instead of just pathlib.Path?

scivision added 2 commits Jun 4, 2018
@scivision
Copy link
Contributor Author

@scivision scivision commented Jun 4, 2018

Thanks, and when I copy these changes into my own Python install, the original error message is no longer issued for my own .py code.

@JelleZijlstra JelleZijlstra merged commit 4890469 into python:master Jun 5, 2018
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants