Skip to content

pathlib.PurePath.__class_getitem__ does not return GenericAlias #90641

Closed

Description

@sobolevn
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']

    Activity

    1. sobolevn commented on Jan 23, 2022

      @sobolevn
      MemberAuthor

      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.

    2. added
      type-bugAn unexpected behavior, bug, or error
      3.11only security fixes
      stdlibStandard Library Python modules in the Lib/ directory
      on Jan 23, 2022
    3. isidentical commented on Jan 23, 2022

      @isidentical
      SponsorMember

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

    4. serhiy-storchaka commented on Jan 23, 2022

      @serhiy-storchaka
      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.

    5. AlexWaygood commented on Jan 23, 2022

      @AlexWaygood
      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

    6. asvetlov commented on Jan 24, 2022

      @asvetlov
      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.

    7. 11 remaining items

    8. AlexWaygood commented on Jan 30, 2022

      @AlexWaygood
      Member

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

    9. added
      type-bugAn unexpected behavior, bug, or error
      and removed on Jan 30, 2022
    10. serhiy-storchaka commented on Feb 3, 2022

      @serhiy-storchaka
      Member

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

    11. serhiy-storchaka commented on Feb 11, 2022

      @serhiy-storchaka
      Member

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

    12. miss-islington commented on Feb 11, 2022

      @miss-islington
      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

    13. miss-islington commented on Feb 11, 2022

      @miss-islington
      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

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions