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
Comments
|
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'): passIt'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. |
|
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). |
|
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). |
|
Excellent! |
|
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. |
|
The CPython PR has gone stale waiting for core review, pinging this per the dev guide. |
|
I'll try to review it in the coming weeks. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: