Skip to content
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

pathlib.PurePath.__class_getitem__ does not return GenericAlias #90641

Closed
sobolevn opened this issue Jan 23, 2022 · 12 comments
Closed

pathlib.PurePath.__class_getitem__ does not return GenericAlias #90641

sobolevn opened this issue Jan 23, 2022 · 12 comments
Labels
3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 46483
Nosy @asvetlov, @serhiy-storchaka, @JelleZijlstra, @miss-islington, @isidentical, @sobolevn, @Fidget-Spinner, @AlexWaygood
PRs
  • bpo-46483: change PurePath.__class_getitem__ to return GenericAlias #30822
  • bpo-46483: remove __class_getitem__ from pathlib.PurePath #30848
  • bpo-46483: [doc] Remove pathlib classes from list of stdlib classes that can be parameterized at runtime #31281
  • [3.9] bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281) #31286
  • [3.10] bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281) #31287
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-02-03.09:24:10.997>
    created_at = <Date 2022-01-23.08:16:30.578>
    labels = ['type-bug', 'library', '3.11']
    title = '`pathlib.PurePath.__class_getitem__` does not return `GenericAlias`'
    updated_at = <Date 2022-02-11.21:04:05.289>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-02-11.21:04:05.289>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-02-03.09:24:10.997>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2022-01-23.08:16:30.578>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46483
    keywords = ['patch']
    message_count = 12.0
    messages = ['411354', '411373', '411374', '411376', '411460', '411518', '411569', '412146', '412430', '413096', '413099', '413100']
    nosy_count = 8.0
    nosy_names = ['asvetlov', 'serhiy.storchaka', 'JelleZijlstra', 'miss-islington', 'BTaskaya', 'sobolevn', 'kj', 'AlexWaygood']
    pr_nums = ['30822', '30848', '31281', '31286', '31287']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46483'
    versions = ['Python 3.11']

    @sobolevn
    Copy link
    Member Author

    After reviewing #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: #17498

    PR is on its way.

    @sobolevn sobolevn added type-bug An unexpected behavior, bug, or error 3.11 only security fixes stdlib Python modules in the Lib dir labels Jan 23, 2022
    @isidentical
    Copy link
    Sponsor Member

    New changeset 1f715d5 by Nikita Sobolev in branch 'main':
    bpo-46483: change PurePath.__class_getitem__ to return GenericAlias (GH-30822)
    1f715d5

    @serhiy-storchaka
    Copy link
    Member

    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.

    @AlexWaygood
    Copy link
    Member

    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

    @asvetlov
    Copy link
    Contributor

    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.

    @desmper121 desmper121 mannequin added topic-email topic-asyncio interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.10 only security fixes and removed type-bug An unexpected behavior, bug, or error labels Jan 24, 2022
    @pablogsal
    Copy link
    Member

    This issue is not related to the parser, so I am unmarking it.

    @pablogsal pablogsal removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 24, 2022
    @serhiy-storchaka
    Copy link
    Member

    It is not related to email and asyncio either.

    @AlexWaygood
    Copy link
    Member

    The desmper121 user appears to be a spammer; I am undoing all the changes they made to this BPO ticket.

    @AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error and removed 3.10 only security fixes labels Jan 30, 2022
    @serhiy-storchaka
    Copy link
    Member

    New changeset 7ffe7ba by Nikita Sobolev in branch 'main':
    bpo-46483: Remove __class_getitem__ from pathlib.PurePath (GH-30848)
    7ffe7ba

    @serhiy-storchaka
    Copy link
    Member

    New changeset e0bc8ee by Alex Waygood in branch 'main':
    bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
    e0bc8ee

    @miss-islington
    Copy link
    Contributor

    New changeset a7c1cc4 by Miss Islington (bot) in branch '3.9':
    bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
    a7c1cc4

    @miss-islington
    Copy link
    Contributor

    New changeset f2fbfbe by Miss Islington (bot) in branch '3.10':
    bpo-46483: [doc] pathlib classes no longer support parameterized generics (GH-31281)
    f2fbfbe

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    7 participants