Skip to content

Change some os.path stubs to acknowledge __fspath__ protocol support in >=Python3.6 #1997

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
brycepg opened this issue Mar 29, 2018 · 0 comments
Assignees

Comments

@brycepg
Copy link
Contributor

brycepg commented Mar 29, 2018

Example:

from pathlib import Path
import os
os.path.join(Path("."), '..')

Is valid python because Python3.6 os.path has been changed to accept the __fspath__ protocol
However mypy outputs:

t.py:3: error: Value of type variable "AnyStr" of "join" cannot be "object"

Relevant location: https://github.com/python/typeshed/blob/master/stdlib/3/os/path.pyi#L79

JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Apr 14, 2018
Fixes python#1997.

This is tricky because we need to get the return values right (see python#1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.

A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
  should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.

I used the following test program to make sure mypy accepted the signatures used here:
@JelleZijlstra JelleZijlstra self-assigned this May 14, 2018
JelleZijlstra added a commit that referenced this issue May 15, 2018
Fixes #1997, #2068.

This is tricky because we need to get the return values right (see #1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.

A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
  should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.
gwk pushed a commit to gwk/typeshed that referenced this issue May 29, 2018
Fixes python#1997, python#2068.

This is tricky because we need to get the return values right (see python#1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.

A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
  should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
Fixes python#1997, python#2068.

This is tricky because we need to get the return values right (see python#1960 for
prior attempts) and we often run into python/mypy#3644. I found that I
could express most signatures correctly using a series of overloads.

A few other changes in here:
- Added splitunc, which according to https://docs.python.org/3/library/os.path.html
  should exist in both Unix and Windows.
- Made the second argument to os.path.curdir Optional to match the implementation.
- Fixed os.path.split, whose previous Path-aware signature triggered python/mypy#3644.
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

2 participants