Skip to content

Clarify make_class argument type #1075

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

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ Core

.. doctest::

>>> C1 = attr.make_class("C1", ["x", "y"])
>>> import attrs
>>> C1 = attrs.make_class("C1", ["x", "y"])
>>> C1(1, 2)
C1(x=1, y=2)
>>> C2 = attr.make_class("C2", {"x": attr.ib(default=42),
... "y": attr.ib(default=attr.Factory(list))})
>>> C2 = attrs.make_class("C2", {
... "x": attrs.field(default=42),
... "y": attrs.field(factory=list)
... })
>>> C2()
C2(x=42, y=[])

Expand Down
4 changes: 2 additions & 2 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -2818,13 +2818,13 @@ def __setstate__(self, state):


def make_class(name, attrs, bases=(object,), **attributes_arguments):
"""
r"""
A quick way to create a new class called *name* with *attrs*.

:param str name: The name for the new class.

:param attrs: A list of names or a dictionary of mappings of names to
attributes.
`attr.ib`\ s / `attrs.field`\ s.

The order is deduced from the order of the names or attributes inside
*attrs*. Otherwise the order of the definition of the attributes is
Expand Down