Skip to content

Commit

Permalink
rewrite mro for class
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Oct 21, 2024
1 parent 49d46b2 commit befffc1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/monty/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from enum import Enum
from hashlib import sha1
from importlib import import_module
from inspect import getfullargspec
from inspect import getfullargspec, isclass
from pathlib import Path
from typing import Any
from uuid import UUID, uuid4
Expand Down Expand Up @@ -105,12 +105,13 @@ class B(A):
list all the types that an object can resolve to in order of generality
(all objects have the builtins.object as the last one).
"""
type_str = type_str if isinstance(type_str, tuple) else (type_str,)
# I believe this try-except is only necessary for callable types
try:
mro = type(obj).mro()
except TypeError:
if isclass(obj):
return False

type_str = type_str if isinstance(type_str, tuple) else (type_str,)

mro = type(obj).mro()

return any(
o.__module__ + "." + o.__qualname__ == ts for o in mro for ts in type_str
)
Expand Down

0 comments on commit befffc1

Please sign in to comment.