[issue41644] builtin type kwargs

Joseph Perez report at bugs.python.org
Wed Aug 26 12:37:38 EDT 2020


New submission from Joseph Perez <joperez at hotmail.fr>:

Class definition can have kwargs which are used by `__init_subclass__` (and `__prepare__`).
However, passing these kwargs using `type` builtin function instead of class definition syntax is not documented; kwargs are not mentioned in the function signature.
https://docs.python.org/3/library/functions.html#type

However, passing kwargs to `type` works:
```python
class Foo:
    def __init_subclass__(cls, **kwargs):
        print(kwargs)
Bar = type("Bar", (Foo,), {}, bar=None) # mypy and Pycharm complain
#> {'bar': None}
```

By the way, the possibility to pass kwargs in `type` call is not documented  in https://docs.python.org/3/reference/datamodel.html#customizing-class-creation too.

----------
assignee: docs at python
components: Documentation
messages: 375936
nosy: docs at python, joperez
priority: normal
severity: normal
status: open
title: builtin type kwargs
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/issue41644>
_______________________________________


More information about the Python-bugs-list mailing list