
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2014-04-01 22:08 byAntony.Lee, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| pathlib.patch | Antony.Lee,2014-04-08 06:21 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg215342 -(view) | Author: Antony Lee (Antony.Lee)* | Date: 2014-04-01 22:08 | |
Trying to construct a Path object from a str subclass, e.g.class S(str): passPath(S("foo"))fails because the subclass cannot be interned. I think that the interning should simply be removed for non-exactly-str arguments (it is only here for performance reasons, right?), or at least the error should be more explicit (note, in particular, that there is no error if one tries 'Path(S("foo/bar"))' instead, which only confuses the matter more).In practice, I found out this via numpy, which provides its own str subclass, numpy.str_. | |||
| msg215741 -(view) | Author: Antony Lee (Antony.Lee)* | Date: 2014-04-08 06:21 | |
The attached patch should fix the issue. | |||
| msg215907 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2014-04-10 20:08 | |
I'm curious: what is the use case for str subclasses in Path objects?If this is to be supported, I think I'd rather force-cast to str rather than accept arbitrary subclasses. | |||
| msg215936 -(view) | Author: Antony Lee (Antony.Lee)* | Date: 2014-04-11 17:41 | |
I am loading some structure from a MATLAB binary file using scipy.io.loadmat. This structure contains (in particular) paths (written as bytestrings) to other files which end up being loaded as numpy.str_ objects.In fact, just trying to store and retrieve strings from numpy arrays wraps them in numpy.str_:>>> import numpy>>> type(numpy.array(["foo"])[0])<class 'numpy.str_'>... and now trying to construct a Path from that will crash.I agree, though, that force-casting str subclasses in the constructor may avoid other issues. | |||
| msg217038 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2014-04-22 22:34 | |
New changesetc24cbd9bd63b by Antoine Pitrou in branch '3.4':Issue#21127: Path objects can now be instantiated from str subclass instances (such as numpy.str_).http://hg.python.org/cpython/rev/c24cbd9bd63bNew changesetaad6d6b819ed by Antoine Pitrou in branch 'default':Issue#21127: Path objects can now be instantiated from str subclass instances (such as numpy.str_).http://hg.python.org/cpython/rev/aad6d6b819ed | |||
| msg217039 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2014-04-22 22:36 | |
Ok, I've committed a patch (to 3.4 and 3.5) that force-casts to str.Thank you for reporting this bug! | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:01 | admin | set | github: 65326 |
| 2014-04-22 22:36:11 | pitrou | set | status: open -> closed versions: + Python 3.4 type: behavior messages: +msg217039 resolution: fixed stage: resolved |
| 2014-04-22 22:34:57 | python-dev | set | nosy: +python-dev messages: +msg217038 |
| 2014-04-11 17:41:53 | Antony.Lee | set | messages: +msg215936 |
| 2014-04-10 20:08:11 | pitrou | set | messages: +msg215907 |
| 2014-04-08 06:21:17 | Antony.Lee | set | files: +pathlib.patch keywords: +patch messages: +msg215741 |
| 2014-04-02 01:26:41 | ned.deily | set | nosy: +pitrou |
| 2014-04-01 22:08:28 | Antony.Lee | create | |