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

Implement PEP 585 (Type Hinting Generics In Standard Collections) #83662

Closed
gvanrossum opened this issue Jan 28, 2020 · 29 comments
Closed

Implement PEP 585 (Type Hinting Generics In Standard Collections) #83662

gvanrossum opened this issue Jan 28, 2020 · 29 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

BPO 39481
Nosy @gvanrossum, @ambv, @serhiy-storchaka, @ethanhs, @miss-islington, @isidentical, @gousaiyang
PRs
  • bpo-39481: Implementation for PEP 585 #18239
  • bpo-39481: Generic alias to os.DirEntry #19415
  • bpo-39481: Generic alias for itertools.chain #19417
  • bpo-39481: Add GenericAlias support to ipaddress.py #19418
  • bpo-39481: Make enumerate, AsyncGeneratorType, mmap generic #19421
  • bpo-39481: PEP 585 for difflib, filecmp, fileinput #19422
  • bpo-39481: PEP 585 for a variety of modules #19423
  • bpo-39481: Make dataclasses.Field, contextvars.Token, ... #19425
  • bpo-39481: Make functools.cached_property, partial, ... #19427
  • bpo-39481: Generic alias support to ctypes.Array, LibraryLoader... #19434
  • bpo-39481: Generic alias support to mp.ValueProxy, mp.ApplyResult, mp… #19435
  • bpo-39481: fix test_genericalias on Android #19469
  • bpo-39481: Make weakref and WeakSet generic #19497
  • bpo-39481: remove generic classes from ipaddress/mmap #20045
  • bpo-39481: Fix duplicate SimpleQueue type in test_genericalias.py #22619
  • [3.9] bpo-39481: Fix duplicate SimpleQueue type in test_genericalias.py (GH-22619) #22624
  • 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 2020-07-25.21:57:06.912>
    created_at = <Date 2020-01-28.17:16:57.906>
    labels = ['interpreter-core', 'type-bug', '3.9']
    title = 'Implement PEP 585 (Type Hinting Generics In Standard Collections)'
    updated_at = <Date 2020-10-12.23:52:11.592>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2020-10-12.23:52:11.592>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-25.21:57:06.912>
    closer = 'gvanrossum'
    components = ['Interpreter Core']
    creation = <Date 2020-01-28.17:16:57.906>
    creator = 'gvanrossum'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39481
    keywords = ['patch']
    message_count = 29.0
    messages = ['360885', '364311', '365357', '365914', '365916', '365936', '365943', '365949', '366102', '366104', '366105', '366106', '366108', '366109', '366131', '366288', '366309', '366311', '366333', '366366', '366367', '366464', '366468', '366476', '367244', '368697', '374286', '378343', '378535']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'lukasz.langa', 'serhiy.storchaka', 'ethan smith', 'miss-islington', 'BTaskaya', 'gousaiyang']
    pr_nums = ['18239', '19415', '19417', '19418', '19421', '19422', '19423', '19425', '19427', '19434', '19435', '19469', '19497', '20045', '22619', '22624']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39481'
    versions = ['Python 3.9']

    @gvanrossum
    Copy link
    Member Author

    See PEP-585, which is still under review and may change in response to this work.

    https://www.python.org/dev/peps/pep-0585/

    @gvanrossum gvanrossum added 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 28, 2020
    @ambv
    Copy link
    Contributor

    ambv commented Mar 16, 2020

    Submitted a request for consideration by the Steering Council: python/steering-council#21

    @gvanrossum
    Copy link
    Member Author

    The SC approved the PEP!

    Łukasz, do you want to submit the PR to update the PEP status?

    We should get the implementation reviewed (e.g. by Serhiy) and land it before alpha 6 goes out, April 22 (we should aim for a week before at least).

    @gvanrossum
    Copy link
    Member Author

    New changeset 48b069a by Guido van Rossum in branch 'master':
    bpo-39481: Implementation for PEP-585 (bpo-18239)
    48b069a

    @gvanrossum
    Copy link
    Member Author

    The base implementation has landed. We still need docs, and I'm sure that the alpha and beta release cycle will find small things that need to be improved.

    Perhaps the next priority is an update for Doc/whatsnew/3.9.rst.

    @isidentical
    Copy link
    Sponsor Member

    @gvanrossum is new types going to support generic alias protocol or this subset will be kept? Like typeshed uses os.DirEntry as a generic, but in reality it is not. (#17561)

    @gvanrossum
    Copy link
    Member Author

    Ethan Smith produced a list of types that are Generic in typeshed but not in the stdlib. So these could be added.

    gvanrossum#1 (comment)

    @gvanrossum
    Copy link
    Member Author

    New changeset f9dd51e by Batuhan Taşkaya in branch 'master':
    bpo-39481: Make os.DirEntry generic (GH-19415)
    f9dd51e

    @gvanrossum
    Copy link
    Member Author

    New changeset 2fa67df by Batuhan Taşkaya in branch 'master':
    bpo-39481: PEP-585 for ipaddress.py (GH-19418)
    2fa67df

    @gvanrossum
    Copy link
    Member Author

    New changeset 7c4185d by Ethan Smith in branch 'master':
    bpo-39481: PEP-585 for enumerate, AsyncGeneratorType, mmap (GH-19421)
    7c4185d

    @gvanrossum
    Copy link
    Member Author

    At this speed I can merge about 3 PRs per hour. I'll be back tomorrow.

    @gvanrossum
    Copy link
    Member Author

    New changeset e3ec44d by Ethan Smith in branch 'master':
    bpo-39481: PEP-585 for difflib, filecmp, fileinput (bpo-19422)
    e3ec44d

    @serhiy-storchaka
    Copy link
    Member

    How are ipaddress and mmap generic?

    @gvanrossum
    Copy link
    Member Author

    Check typeshed

    @gvanrossum
    Copy link
    Member Author

    New changeset 0361556 by Batuhan Taşkaya in branch 'master':
    bpo-39481: PEP-585 for a variety of modules (GH-19423)
    0361556

    @serhiy-storchaka
    Copy link
    Member

    I tested the following example:

    import ipaddress, mmap

    x: ipaddress.IPv4Network[int]
    y: mmap.mmap[int]

    MyPy produces errors:

    t.py:4: error: "IPv4Network" expects no type arguments, but 1 given
    t.py:5: error: "mmap" expects no type arguments, but 1 given

    This is because mmap and IPv4Network are not generic types in typeshed. _BaseNetwork and _mmap are generic types, but IPv4Network and mmap are normal classes. The former are implementation detail of typeshed. _mmap does not exist in the stdlib, and _BaseNetwork in typeshed and the stdlib are different things.

    @ethanhs
    Copy link
    Mannequin

    ethanhs mannequin commented Apr 13, 2020

    Hm, yeah it appears my methodology was too loose. Thank you for catching
    these. I will go through and test the rest (if you haven't yet) later today
    and make a PR to revert anything that needs it. Thanks! (and sorry)

    On Mon, Apr 13, 2020 at 2:12 AM Serhiy Storchaka <report@bugs.python.org>
    wrote:

    Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:

    I tested the following example:

    import ipaddress, mmap

    x: ipaddress.IPv4Network[int]
    y: mmap.mmap[int]

    MyPy produces errors:

    t.py:4: error: "IPv4Network" expects no type arguments, but 1 given
    t.py:5: error: "mmap" expects no type arguments, but 1 given

    This is because mmap and IPv4Network are not generic types in typeshed.
    _BaseNetwork and _mmap are generic types, but IPv4Network and mmap are
    normal classes. The former are implementation detail of typeshed. _mmap
    does not exist in the stdlib, and _BaseNetwork in typeshed and the stdlib
    are different things.

    ----------


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue39481\>


    @serhiy-storchaka
    Copy link
    Member

    No, I did not check other changes. These two just looked too suspicious.

    @gvanrossum
    Copy link
    Member Author

    New changeset 25a6833 by Chih-Hsuan Yen in branch 'master':
    bpo-39481: fix test_genericalias on Android (GH-19469)
    25a6833

    @gvanrossum
    Copy link
    Member Author

    New changeset cecf049 by Ethan Smith in branch 'master':
    bpo-39481: Make functools.cached_property, partial, partialmethod generic (bpo-19427)
    cecf049

    @gvanrossum
    Copy link
    Member Author

    New changeset 8ef8750 by Ethan Smith in branch 'master':
    bpo-39481: Make weakref and WeakSet generic (GH-19497)
    8ef8750

    @gvanrossum
    Copy link
    Member Author

    New changeset d01628e by Ethan Smith in branch 'master':
    bpo-39481: PEP-585 for dataclasses, mailbox, contextvars (GH-19425)
    d01628e

    @ethanhs
    Copy link
    Mannequin

    ethanhs mannequin commented Apr 15, 2020

    I went through the list I generated and it seems that the
    ipaddress._BaseNetwork and mmap.mmap cases are the only one I saw that
    shouldn't be generic. I will submit a PR to revert those. The only item
    left after that which I know of is _lru_cache_wrapper.

    On Tue, Apr 14, 2020 at 4:14 PM Guido van Rossum <report@bugs.python.org>
    wrote:

    Guido van Rossum <guido@python.org> added the comment:

    New changeset d01628e by Ethan Smith in
    branch 'master':
    bpo-39481: PEP-585 for dataclasses, mailbox, contextvars (GH-19425)

    d01628e

    ----------


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue39481\>


    @gvanrossum
    Copy link
    Member Author

    Thanks!

    --Guido (mobile)

    @gvanrossum
    Copy link
    Member Author

    In commit 0e80b56 a What's New section was added.

    @gvanrossum
    Copy link
    Member Author

    New changeset f3a5b7a by Batuhan Taskaya in branch 'master':
    bpo-39481: remove generic classes from ipaddress/mmap (GH-20045)
    f3a5b7a

    @gvanrossum
    Copy link
    Member Author

    This can be closed. It needs docs though; there's a separate issue for that (bpo-40814).

    @miss-islington
    Copy link
    Contributor

    New changeset b2c0a43 by Saiyang Gou in branch 'master':
    bpo-39481: Fix duplicate SimpleQueue type in test_genericalias.py (GH-22619)
    b2c0a43

    @gvanrossum
    Copy link
    Member Author

    New changeset 1c21765 by Saiyang Gou in branch '3.9':
    [3.9] bpo-39481: Fix duplicate SimpleQueue type in test_genericalias.py (GH-22619) (bpo-22624)
    1c21765

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants