Skip to content

Commit bb6f7f6

Browse files
committed
Update docs and add new test
1 parent 1dfee65 commit bb6f7f6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Doc/library/dataclasses.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ Module-level decorators, classes, and functions
174174
section.
175175

176176
- ``slots``: If true (the default is ``False``), :attr:`__slots__` attribute
177-
will be generated. If :attr:`__slots__` is defined in the class, then
178-
:exc:`TypeError` is raised.
177+
will be generated and new class will be returned instead of original one.
178+
If :attr:`__slots__` is defined in the class, then :exc:`TypeError`
179+
is raised.
179180

180181
``field``\s may optionally specify a default value, using normal
181182
Python syntax::

Lib/test/test_dataclasses.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,16 @@ class AnotherDelivered(Base):
28232823

28242824
self.assertTrue('__slots__' not in AnotherDelivered.__dict__)
28252825

2826+
def test_returns_new_class(self):
2827+
class A:
2828+
x: int
2829+
2830+
B = dataclass(A, slots=True)
2831+
self.assertIsNot(A, B)
2832+
2833+
self.assertFalse(hasattr(A, "__slots__"))
2834+
self.assertTrue(hasattr(B, "__slots__"))
2835+
28262836

28272837
class TestDescriptors(unittest.TestCase):
28282838
def test_set_name(self):

0 commit comments

Comments
 (0)