Skip to content

Commit

Permalink
Fix __init__ + __init_subclass__ + AbstractClassVar
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-kidger committed Sep 18, 2024
1 parent 31b554f commit 804d82e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions equinox/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,10 @@ def _is_abstract(cls):


class _Initable:
pass
# Prevent `__init_subclass__` from triggering when creating initable versions of
# classes.
def __init_subclass__(cls, **kwargs):
del kwargs


_transform_types = {
Expand Down Expand Up @@ -805,7 +808,7 @@ def _make_initable(
else:
field_names = {field.name for field in dataclasses.fields(cls)}

class _InitableModule(cls, _Initable):
class _InitableModule(_Initable, cls):
pass

def __setattr__(self, name, value):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,3 +1204,20 @@ class E(D, B):
assert called_a
assert called_b
assert called_d


# https://github.com/patrick-kidger/equinox/issues/858
def test_init_subclass_and_abstract_class_var():
class Parent(eqx.Module):
abs_cls_var: eqx.AbstractClassVar[str]

def __init__(self):
pass

def __init_subclass__(cls):
cls.abs_cls_var

class Child(Parent):
abs_cls_var = "foo"

Child() # pyright: ignore[reportCallIssue]

0 comments on commit 804d82e

Please sign in to comment.