Fixed working with the new (unreleased) version of typeguard (#53)

This commit is contained in:
Patrick Kidger
2022-12-29 17:46:25 +00:00
committed by GitHub
parent 2b1be5eb0a
commit c4c3674549
3 changed files with 29 additions and 6 deletions
+1 -1
View File
@@ -89,4 +89,4 @@ elif has_jax:
del has_jax
__version__ = "0.2.9"
__version__ = "0.2.10"
+9 -1
View File
@@ -59,6 +59,14 @@ class _MetaPyTree(type):
return out
try:
# new typeguard
_TypeCheckError = (TypeError, typeguard.TypeCheckError)
except AttributeError:
# old typeguard
_TypeCheckError = TypeError
class _MetaSubscriptPyTree(type):
def __call__(self, *args, **kwargs):
raise RuntimeError("PyTree cannot be instantiated")
@@ -77,7 +85,7 @@ class _MetaSubscriptPyTree(type):
def is_leaftype(x):
try:
accepts_leaftype(x)
except TypeError:
except _TypeCheckError:
return False
else:
return True
+19 -4
View File
@@ -18,16 +18,31 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import equinox as eqx
import typeguard
ParamError = []
ReturnError = []
ParamError.append(TypeError) # old typeguard
ReturnError.append(TypeError) # old typeguard
try:
# new typeguard
ParamError.append(typeguard.TypeCheckError)
ReturnError.append(typeguard.TypeCheckError)
except AttributeError:
pass
try:
import beartype
except ImportError:
ParamError = TypeError
ReturnError = TypeError
pass
else:
ParamError = (TypeError, beartype.roar.BeartypeCallHintParamViolation)
ReturnError = (TypeError, beartype.roar.BeartypeCallHintReturnViolation)
ParamError.append(beartype.roar.BeartypeCallHintParamViolation)
ReturnError.append(beartype.roar.BeartypeCallHintReturnViolation)
ParamError = tuple(ParamError)
ReturnError = tuple(ReturnError)
@eqx.filter_jit