Added support for 'self' in dataclass attribute annotations; switched from args and kwargs to just arguments.

This commit is contained in:
Patrick Kidger
2023-11-27 09:50:02 -08:00
parent 80a99568f7
commit 5fbd6718ab
3 changed files with 49 additions and 28 deletions
+15
View File
@@ -17,6 +17,7 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import dataclasses as dc
import sys
from typing import get_args, get_origin, Union
@@ -33,6 +34,7 @@ from jaxtyping import (
Bool,
Float,
Float32,
jaxtyped,
Key,
PRNGKeyArray,
Scalar,
@@ -485,6 +487,19 @@ def test_deferred_symbolic_bad(jaxtyp, typecheck):
A().bar(jnp.array(0.0))
def test_deferred_symbolic_dataclass(typecheck):
@jaxtyped(typechecker=typecheck)
@dc.dataclass
class A:
value: int
array: Float[Array, " {self.value}"]
A(3, jnp.zeros(3))
with pytest.raises(ParamError):
A(3, jnp.zeros(4))
def test_arraylike(typecheck, getkey):
floatlike1 = Float32[ArrayLike, ""]
floatlike2 = Float[ArrayLike, ""]