-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Using os.PathLike as an annotation #5667
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
Comments
I think the fix is to quote the type so that it is not evaluated at runtime:
|
Another solution is to use This problem appeared several times. It would be great to create a documentation entry about this. |
Oh of course, how could I have forgotten about the string version of annotations!? +1 to a mention in documentation |
Another example is when the class that is generic in typeshed is not generic at runtime appears as a base class. This case is even more important, since one can't use quotes and |
Summary: python/mypy#5667 python/typeshed#3202 Reviewed By: fabianschenk Differential Revision: D35423993 fbshipit-source-id: 73e2027ea425eb629d6faa864aa0829d59997b07
I am trying to create a typealias for all the types that can be passed as the first argument of
open()
. MyPy reveals the type to beUnion[builtins.str, builtins.bytes, builtins.int, builtins._PathLike[Any]]
.My first attempt at this is:
MyPy is happy with this, but alas Python is not:
Trying this, then:
But now MyPy is unhappy:
What is the correct way of using
os.PathLike
here? There is notyping.PathLike
yet. Do I have to create my own generic version ofos.PathLike
?The text was updated successfully, but these errors were encountered: