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]] = ...,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@scivision
Copy link
Contributor Author

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
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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants