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: builtin type kwargs
Type: Stage:
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ethan.furman, joperez, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-08-26 16:37 by joperez, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg375936 - (view) Author: Joseph Perez (joperez) * Date: 2020-08-26 16:37
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.
msg375939 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-26 17:01
It is rather an issue of MyPy and PyCharm. The Python interpreter itself does not perform static type testing and does not provide annotations for builtins.
msg375954 - (view) Author: Joseph Perez (joperez) * Date: 2020-08-26 18:51
That's why it's not an interpreter issue but a lack in the official documentation where the signature is documented.
I quote https://docs.python.org/3/library/functions.html#type:
> class type(object)
> class type(name, bases, dict)

The second line should be "class type(name, bases, dict, **kwargs)".

(I've mentioned Pycharm and Mypy, but i think it's a kind of side-effect of the incomplete official documentation on which is based their typeshed)

In fact, I've raised this issue because I've found myself needing to instantiate a class using `type` and kwargs, and I've not found in the documentation an example of it.
History
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85810
2020-12-24 22:06:00ethan.furmansetnosy: + ethan.furman
2020-08-26 18:51:12joperezsetmessages: + msg375954
2020-08-26 17:01:10serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg375939
2020-08-26 16:37:38joperezcreate