This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: `pathlib.PurePath.__class_getitem__` does not return `GenericAlias`
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, BTaskaya, JelleZijlstra, asvetlov, kj, miss-islington, serhiy.storchaka, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-23 08:16 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30822 merged sobolevn, 2022-01-23 08:19
PR 30848 merged sobolevn, 2022-01-24 10:06
PR 31281 merged AlexWaygood, 2022-02-11 16:37
PR 31286 merged miss-islington, 2022-02-11 20:39
PR 31287 merged miss-islington, 2022-02-11 20:42
Messages (12)
msg411354 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-23 08:16
After reviewing https://github.com/python/cpython/pull/30777 I had a chance to look through other definitions of `def __class_getitem__`. And I found that the only one left is: `pathlib.PurePath.__class_getitem__`

All other definitions already have this form: `__class_getitem__ = classmethod(GenericAlias)`.

I don't think that there's anything special about `PurePath` in this regard. So, I propose to make `__class_getitem__` to return `GenericAlias` as all other types do.

Initial PR: https://github.com/python/cpython/pull/17498

PR is on its way.
msg411373 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2022-01-23 14:48
New changeset 1f715d5bd3bc9ff444e109b6bbd13011913681b1 by Nikita Sobolev in branch 'main':
bpo-46483: change `PurePath.__class_getitem__` to return `GenericAlias` (GH-30822)
https://github.com/python/cpython/commit/1f715d5bd3bc9ff444e109b6bbd13011913681b1
msg411374 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-23 14:52
Why __class_getitem__ was added in PurePath at first place? PurePath should not be a generic class, unlike to os.PathLike. For os.PathLike the type parameters represent the returning type of os.fspath() (either str or bytes), but the pathlib module only supports paths as strings, so no parametrization is needed.

I think PurePath.__class_getitem__ should be removed.
msg411376 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-01-23 15:09
It looks like __class_getitem__ was added to PurePath at @asvetlov's request  in PR 17498. But, I'm also not quite sure why. The class is not generic in typeshed, so type-checkers will raise an error if you do PurePath[str], even if it is possible to do so at runtime.

Typeshed stub for PurePath: https://github.com/python/typeshed/blob/dff461fc6adef1ec3a4b58af5abdf0cdebf2429a/stdlib/pathlib.pyi#L20
msg411460 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-01-24 10:17
IIRC it was added to reflect the presence of __class_getitem__ method in typeshed.
Please feel free to drop it the method is not really needed.
msg411518 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-24 21:45
This issue is not related to the parser, so I am unmarking it.
msg411569 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-25 09:44
It is not related to email and asyncio either.
msg412146 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-01-30 13:44
The desmper121 user appears to be a spammer; I am undoing all the changes they made to this BPO ticket.
msg412430 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-02-03 09:25
New changeset 7ffe7ba30fc051014977c6f393c51e57e71a6648 by Nikita Sobolev in branch 'main':
bpo-46483: Remove `__class_getitem__` from `pathlib.PurePath` (GH-30848)
https://github.com/python/cpython/commit/7ffe7ba30fc051014977c6f393c51e57e71a6648
msg413096 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-02-11 20:39
New changeset e0bc8ee945af96f9395659bbe3cc30b082e7a361 by Alex Waygood in branch 'main':
bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
https://github.com/python/cpython/commit/e0bc8ee945af96f9395659bbe3cc30b082e7a361
msg413099 - (view) Author: miss-islington (miss-islington) Date: 2022-02-11 21:03
New changeset a7c1cc41696740bb528f4d24816c59e38b8be345 by Miss Islington (bot) in branch '3.9':
bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
https://github.com/python/cpython/commit/a7c1cc41696740bb528f4d24816c59e38b8be345
msg413100 - (view) Author: miss-islington (miss-islington) Date: 2022-02-11 21:04
New changeset f2fbfbe0ec57ec39b3099dae62571a48d5fe8729 by Miss Islington (bot) in branch '3.10':
bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
https://github.com/python/cpython/commit/f2fbfbe0ec57ec39b3099dae62571a48d5fe8729
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90641
2022-02-11 21:04:05miss-islingtonsetmessages: + msg413100
2022-02-11 21:03:57miss-islingtonsetmessages: + msg413099
2022-02-11 20:42:20miss-islingtonsetpull_requests: + pull_request29447
2022-02-11 20:39:52miss-islingtonsetnosy: + miss-islington

pull_requests: + pull_request29446
2022-02-11 20:39:48serhiy.storchakasetmessages: + msg413096
2022-02-11 16:37:38AlexWaygoodsetpull_requests: + pull_request29441
2022-02-03 09:25:27serhiy.storchakasetmessages: + msg412430
2022-02-03 09:24:10serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-30 13:44:46AlexWaygoodsetversions: - Python 3.10
nosy: - barry, r.david.murray, yselivanov, lys.nikolaou, pablogsal

messages: + msg412146

type: behavior
2022-01-25 09:44:00serhiy.storchakasetmessages: + msg411569
components: - email, asyncio
2022-01-24 21:45:13pablogsalsetnosy: barry, r.david.murray, asvetlov, serhiy.storchaka, yselivanov, JelleZijlstra, lys.nikolaou, pablogsal, BTaskaya, sobolevn, kj, AlexWaygood
messages: + msg411518
components: - Parser
2022-01-24 21:25:52desmper121setnosy: + barry, yselivanov, r.david.murray, lys.nikolaou, pablogsal

type: behavior -> (no value)
components: + email, asyncio, Parser
versions: + Python 3.10
2022-01-24 20:51:42gvanrossumsetnosy: - gvanrossum
2022-01-24 17:51:30JelleZijlstrasetnosy: + JelleZijlstra
2022-01-24 10:17:38asvetlovsetmessages: + msg411460
2022-01-24 10:06:49sobolevnsetpull_requests: + pull_request29030
2022-01-23 15:09:18AlexWaygoodsetnosy: + AlexWaygood, asvetlov
messages: + msg411376
2022-01-23 14:52:11serhiy.storchakasetnosy: + gvanrossum, kj, serhiy.storchaka
messages: + msg411374
2022-01-23 14:48:48BTaskayasetnosy: + BTaskaya
messages: + msg411373
2022-01-23 08:19:01sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29009
2022-01-23 08:16:30sobolevncreate