-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
os.path should use AnyStr, not unicode #50
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
The Python 3 stub uses
The Python 2 stub uses |
I don't have a problem with mypy injecting the artificial subtype relationship In mypy, is there any practical difference between |
If/when we add some language about Python 2 to PEP 484, we may consider making the
Using
|
I created a mypy issue for discussing how mypy should deal with this: python/mypy#1141. We could also move this to typehinting or python-ideas. |
Remembering our email discussion about simplifying types, it seems to me that replacing I'm still making up my mind about the
. So the only remaining thing I wonder about is whether some user-space code would want to limit types to unicode as a preparatory mesaure for Python 2->3 conversion. If so, it wouldn't have a way to do that with the implicit subclassing in place. |
Also, it's important that the return type is Limiting str/unicode compatibility is a reasonable use case, but a likely better way to do it is to run a type checker in Python 3 mode. It will also catch other Python 2/3 errors. |
I think you missed something; it seems to follow the first arg.
But reading the code that's hard to figure out (it calls commonprefix() on But in the case of the most things in os and os.path, I have a feeling we |
I just read Jukka's reply (even though it came before mine). I would like to have a clear proposal. My proposal is to use AnyStr everywhere for os and os.path, and just explain when users complain that their code is suspect at best. (If using a type variable in one position is a problem, we can use basestring for those.) Can we vote on this? |
Note that Anyway, I believe that experimentation with production code is the right way to understand this issue better. The problem is that for each experiment we may have to update all relevant stubs :-/ |
Regarding Guido's previous comment, using |
To be renamed into stdlib/2and3/os/path.pyi later. Also fixes python#50
* Merge stdlib/{2,3}/os/path.pyi To be renamed into stdlib/2and3/os/path.pyi later. Also fixes #50 * CR fixes
os.path
currently defines everything as usingunicode
. But most functions accept bothstr
andunicode
.E.g.
os.path.isdir
usesos.stat()
underneath, which does PyArg_ParseTuple(args, "et"). Hence it supportsstr
andunicode
. (And character buffer objects, for that matter)os.path
should useAnyStr
.The text was updated successfully, but these errors were encountered: