Skip to content

Commit

Permalink
fix(utility): fix TypeError when using "_repr1" on type with _repr_type
Browse files Browse the repository at this point in the history
PR Closed: #1258
  • Loading branch information
Lee-000 committed Jun 22, 2022
1 parent dcdabbb commit 98d376f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tensorbay/utility/repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@

from abc import ABC
from enum import Enum, auto
from typing import Any, Callable, Dict, Iterable, Mapping, Sequence, Tuple, Type, TypeVar, Union
from typing import (
Any,
Callable,
ClassVar,
Dict,
Iterable,
Mapping,
Sequence,
Tuple,
Type,
TypeVar,
Union,
)


class ReprType(Enum):
Expand All @@ -25,7 +37,7 @@ class ReprType(Enum):
class ReprMixin:
"""ReprMixin provides customized repr config and method."""

_repr_type = ReprType.INSTANCE
_repr_type: ClassVar[ReprType] = ReprType.INSTANCE
_repr_attrs: Iterable[str] = ()
_repr_maxlevel = 1
_repr_non_empty = False
Expand Down Expand Up @@ -129,8 +141,8 @@ def _repr1(obj: Any, level: int, maxlevel: int, folding: bool) -> str:
"""
# pylint: disable=protected-access
printer_key = obj._repr_type if hasattr(obj, "_repr_type") else type(obj)
printer = _PRINTERS.get(printer_key, None)
class_ = type(obj)
printer = _PRINTERS.get(getattr(class_, "_repr_type", class_), None)
return printer(obj, level, maxlevel, folding) if printer else repr(obj)


Expand Down

0 comments on commit 98d376f

Please sign in to comment.