-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dataclasses now have fields checked, not __init__.
Previously, using the import hook with dataclasses resulted in the `__init__` method of the dataclass being checked. This was undesirable when using `eqx.field(converter=...)`, as the annotation didn't necessarily reflect the argument type. A typical example was ```python class Foo(eqx.Module): x: jax.Array = eqx.field(converter=jnp.ndarray) Foo(1) # 1 is not an array! But this code is valid. ``` After this change, we instead monkey-patch our checks to happen at the end of the `__init__` of the dataclass -- after conversion has run. Note that this requires patrick-kidger/equinox#524. Otherwise, Equinox does conversion too late (in `_ModuleMeta.__call__`, after `__init__` has been run).
- Loading branch information
1 parent
17092ad
commit 0d36472
Showing
3 changed files
with
192 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters