X Tutup
The Wayback Machine - https://web.archive.org/web/20220512051210/https://github.com/python/cpython/issues/87006
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

type takes **kwargs for __init_subclass__ #87006

Open
esoma mannequin opened this issue Jan 6, 2021 · 10 comments
Open

type takes **kwargs for __init_subclass__ #87006

esoma mannequin opened this issue Jan 6, 2021 · 10 comments
Labels
3.7 3.8 3.9 3.10 type-bug

Comments

@esoma
Copy link
Mannequin

@esoma esoma mannequin commented Jan 6, 2021

BPO 42840
Nosy @gvanrossum, @miss-islington, @esoma
PRs
  • #24173
  • #24695
  • #24696
  • 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 = None
    created_at = <Date 2021-01-06.15:21:21.491>
    labels = ['3.8', 'type-bug', '3.7', '3.9', '3.10']
    title = '`type` takes **kwargs for __init_subclass__'
    updated_at = <Date 2021-04-01.00:10:39.759>
    user = 'https://github.com/esoma'

    bugs.python.org fields:

    activity = <Date 2021-04-01.00:10:39.759>
    actor = 'miss-islington'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2021-01-06.15:21:21.491>
    creator = 'esoma'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42840
    keywords = ['patch']
    message_count = 10.0
    messages = ['384506', '384522', '384530', '384533', '384707', '387271', '387280', '387883', '387884', '389941']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'miss-islington', 'esoma']
    pr_nums = ['24173', '24695', '24696']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42840'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @esoma
    Copy link
    Mannequin Author

    @esoma esoma mannequin commented Jan 6, 2021

    The documentation (https://docs.python.org/3/library/functions.html#type) shows type's signature as:

    class type(object)
    class type(name, bases, dict)

    But the "actual" 2nd signature in CPython 3.6+ is:

    class type(name, bases, dict, **kwargs)

    **kwargs here gets passed to __init_subclass__ in the same way that keywords in a class statement do so that:

    type("Bar", (Foo,), {}, spam='ham')

    is equivalent to

    class Bar(Foo, spam='ham'): pass

    It's not clear to me whether this is behavior to rely on. I started using this intuitively, but found that my type checker reasonably complained.

    Looking through the commit that implemented PEP-487 (d78448e), it seems this may have been incidental. Additionally I haven't found mention of this in PEP-487 or the documentation and I can't seem to find any tests for it.

    @esoma esoma mannequin added 3.7 3.8 3.9 3.10 type-bug labels Jan 6, 2021
    @gvanrossum
    Copy link
    Member

    @gvanrossum gvanrossum commented Jan 6, 2021

    That sounds intentional to me (else the class statement would have a capability that cannot be dynamically emulated by calling type()).

    We should probably update the docs (if you could submit a small PR that would be appreciated) and also typeshed (ditto).

    @esoma
    Copy link
    Mannequin Author

    @esoma esoma mannequin commented Jan 6, 2021

    Can do.

    I have found a blurb in the 3.6 What's New that confirms it was purposeful (https://docs.python.org/3/whatsnew/3.6.html#index-37).

    @gvanrossum
    Copy link
    Member

    @gvanrossum gvanrossum commented Jan 6, 2021

    Excellent!

    @esoma
    Copy link
    Mannequin Author

    @esoma esoma mannequin commented Jan 9, 2021

    Seems I misframed the issue a bit. I didn't realize keyword arguments besides 'metaclass' were introduced with PEP-3115 with Python 3.0.

    In any case I've posted a PR to update the docs and typeshed.
    Typeshed PR for reference: python/typeshed#4918

    @esoma
    Copy link
    Mannequin Author

    @esoma esoma mannequin commented Feb 18, 2021

    The CPython PR has gone stale waiting for core review, pinging this per the dev guide.

    @gvanrossum
    Copy link
    Member

    @gvanrossum gvanrossum commented Feb 19, 2021

    I'll try to review it in the coming weeks.

    @gvanrossum
    Copy link
    Member

    @gvanrossum gvanrossum commented Mar 1, 2021

    New changeset 72fcd14 by Erik Soma in branch 'master':
    bpo-42840: Document providing kwargs to type. (bpo-24173)
    72fcd14

    @miss-islington
    Copy link
    Contributor

    @miss-islington miss-islington commented Mar 1, 2021

    New changeset 7101d15 by Miss Islington (bot) in branch '3.8':
    bpo-42840: Document providing kwargs to type. (GH-24173)
    7101d15

    @miss-islington
    Copy link
    Contributor

    @miss-islington miss-islington commented Apr 1, 2021

    New changeset b3c1e2c by Miss Islington (bot) in branch '3.9':
    bpo-42840: Document providing kwargs to type. (GH-24173)
    b3c1e2c

    @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.7 3.8 3.9 3.10 type-bug
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants
    X Tutup