[New-bugs-announce] [issue42840] `type` takes **kwargs for __init_subclass__
Erik Soma
report at bugs.python.org
Wed Jan 6 10:21:21 EST 2021
New submission from Erik Soma <stillusingirc at gmail.com>:
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.
----------
messages: 384506
nosy: esoma
priority: normal
severity: normal
status: open
title: `type` takes **kwargs for __init_subclass__
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42840>
_______________________________________
More information about the New-bugs-announce
mailing list