-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Update open
, os.fspath
, os.fsencode
, os.fsdecode
, pathlib.PurePath
and pathlib.Path
stubs due to PEP-519
#991
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
Conversation
This change looks good to me but there's a lot more to be done in relation to PEP 519. First, many additional functions should be updated to accept os.PathLike in addition to str for paths. We should maybe add a type alias ( Also, Anyway, those issues are outside the scope of this PR. I'll think about them more and maybe write up a proposal. |
stdlib/3/os/__init__.pyi
Outdated
def fsencode(filename: str) -> bytes: ... | ||
def fsdecode(filename: bytes) -> str: ... | ||
if sys.version_info >= (3, 6): | ||
def fsencode(filename: Union[str, PathLike]) -> bytes: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually also accepts bytes, and this is documented at https://docs.python.org/3/library/os.html#os.fsencode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
**kwargs: Any) -> _P: ... | ||
if sys.version_info < (3, 6): | ||
def __new__(cls: Type[_P], *args: Union[str, PurePath], | ||
**kwargs: Any) -> _P: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, apparently Path takes arbitrary kwargs and then ignores them. This doesn't appear to be documented. Do you know why this is? I might open a bug against CPython about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I think it is better to open a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need python/typeshed#991 for proper checking
open
, os.fspath
, os.fsencode
, os.fsdecode
, pathlib.PurePath
and pathlib.Path
stubs due to PEP-519
stdlib/3/os/__init__.pyi
Outdated
@overload | ||
def fspath(path: bytes) -> bytes: ... | ||
@overload | ||
def fspath(path: PathLike) -> Union[str, bytes]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have this overload return Any since Union return types are troublesome. Sorry for not noticing this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
…rn types are troublesome
Thanks! |
Sadly I have to revert one part of this PR -- the changes to builtins.pyi introduced a new element in mypy's "bootstrap" import cycle (by adding a
All that only for Python 3.6. |
This reverts commit 48b271c. See #991 (comment) for details; basically this disturbed mypy's bootstrap import cycle.
Oh no. :( Why didn't Travis catch this? |
Good question. I think the travis mypy test script runs mypy with a whole bunch of filenames (of stub files) as arguments, and that may force a different processing order. Maybe we should add a plain |
Yeah, it would be totally worth it to run mypy's own testsuite against typeshed. There are two risks:
This would make the life of Dropboxers easier by providing early warnings if something would fail when syncing the submodule. |
Can either of you create a new issue for this? I don't like new discussions under closed issues/PRs if it's not directly "this broke X". |
Summary: python/typeshed#991 (comment) Reviewed By: sinancepel Differential Revision: D8335824 fbshipit-source-id: 7926319534b9e0bb8039d7786a1dc56a9da2eeb5
Update stubs for:
open
functionos.path
,os.fsencode
andos.fsdecode
functionspathlib.PurePath
andpathlib.Path
classesdue to PEP-519.