patrick-kidger / torchtyping

Type annotations and dynamic checking for a tensor's shape, dtype, names, etc.
Apache License 2.0
1.41k stars 34 forks source link

Fix typeguard upper bound #46

Closed MilesCranmer closed 1 year ago

MilesCranmer commented 1 year ago

The current package breaks on typeguard>=3 due to the following error:

  File "/.../test2.py", line 13, in <module>
    patch_typeguard()  # use before @typechecked
  File "/.../python3.10/site-packages/torchtyping/typechecker.py", line 271, in patch_typeguard
    class _CallMemo(typeguard._CallMemo):
  File "/.../python3.10/site-packages/typeguard/__init__.py", line 42, in __getattr__
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
AttributeError: module 'typeguard' has no attribute '_CallMemo'. Did you mean: 'CallMemo'?

So this just limits the typeguard install to <3 which fixes things. It looks like a few functions need to be rewritten on >=3 so this is a simple band-aid fix.

(I understand this package isn't actively maintained, but until https://github.com/google/jaxtyping/issues/6 is closed, I find this package a bit more useful, even though you mention the patch_typeguard felt a bit hacky 😄)

patrick-kidger commented 1 year ago

LGTM, thank you!