Skip to content

Commit

Permalink
Merge branch 'main' into typing.dataclass_transform
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek authored Jun 27, 2023
2 parents 0a7598a + 261d26e commit 5312d68
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_init_subclass.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT

"""
Tests for `__init_subclass__` related tests.
Tests for `__init_subclass__` related functionality.
"""

import attr
Expand Down Expand Up @@ -41,3 +41,26 @@ class Attrs(Base, param="foo"):
pass

assert "foo" == Attrs().param


def test_init_subclass_slots_workaround():
"""
`__init_subclass__` works with modern APIs if care is taken around classes
existing twice.
"""
subs = {}

@attr.define
class Base:
def __init_subclass__(cls):
subs[cls.__qualname__] = cls

@attr.define
class Sub1(Base):
x: int

@attr.define
class Sub2(Base):
y: int

assert (Sub1, Sub2) == tuple(subs.values())

0 comments on commit 5312d68

Please sign in to comment.