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: `type` takes **kwargs for __init_subclass__
Type: behavior Stage: patch review
Components: Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: esoma, gvanrossum, miss-islington
Priority: normal Keywords: patch

Created on 2021-01-06 15:21 by esoma, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 24173 merged esoma, 2021-01-08 21:11
PR 24695 merged miss-islington, 2021-03-01 23:21
PR 24696 merged miss-islington, 2021-03-01 23:21
Messages (10)
msg384506 - (view) Author: Erik Soma (esoma) * Date: 2021-01-06 15:21
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 (d78448e9), 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.
msg384522 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-06 17:36
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).
msg384530 - (view) Author: Erik Soma (esoma) * Date: 2021-01-06 18:37
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).
msg384533 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-06 19:00
Excellent!
msg384707 - (view) Author: Erik Soma (esoma) * Date: 2021-01-09 01:49
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: https://github.com/python/typeshed/pull/4918
msg387271 - (view) Author: Erik Soma (esoma) * Date: 2021-02-18 21:18
The CPython PR has gone stale waiting for core review, pinging this per the dev guide.
msg387280 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-02-19 03:20
I'll try to review it in the coming weeks.
msg387883 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-03-01 23:21
New changeset 72fcd14a82369ed32a5846d76f50e3026cf4eec2 by Erik Soma in branch 'master':
bpo-42840: Document providing kwargs to type. (#24173)
https://github.com/python/cpython/commit/72fcd14a82369ed32a5846d76f50e3026cf4eec2
msg387884 - (view) Author: miss-islington (miss-islington) Date: 2021-03-01 23:30
New changeset 7101d152f9789ad243912c00349d5da657b217fd by Miss Islington (bot) in branch '3.8':
bpo-42840: Document providing kwargs to type. (GH-24173)
https://github.com/python/cpython/commit/7101d152f9789ad243912c00349d5da657b217fd
msg389941 - (view) Author: miss-islington (miss-islington) Date: 2021-04-01 00:10
New changeset b3c1e2c493e67f84b1034ac6c49492a459b0736d by Miss Islington (bot) in branch '3.9':
bpo-42840: Document providing kwargs to type. (GH-24173)
https://github.com/python/cpython/commit/b3c1e2c493e67f84b1034ac6c49492a459b0736d
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 87006
2021-04-01 00:10:39miss-islingtonsetmessages: + msg389941
2021-03-01 23:30:49miss-islingtonsetmessages: + msg387884
2021-03-01 23:21:25gvanrossumsetmessages: + msg387883
2021-03-01 23:21:22miss-islingtonsetpull_requests: + pull_request23473
2021-03-01 23:21:14miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23472
2021-02-19 03:20:13gvanrossumsetmessages: + msg387280
2021-02-18 21:18:08esomasetmessages: + msg387271
2021-01-09 01:49:33esomasetmessages: + msg384707
2021-01-08 21:11:44esomasetkeywords: + patch
stage: patch review
pull_requests: + pull_request23000
2021-01-06 19:00:05gvanrossumsetmessages: + msg384533
2021-01-06 18:37:18esomasetmessages: + msg384530
2021-01-06 17:36:24gvanrossumsetnosy: + gvanrossum
messages: + msg384522
2021-01-06 15:21:21esomacreate