diff --git a/genesis/datatypes.py b/genesis/datatypes.py index 8396036..c15b044 100644 --- a/genesis/datatypes.py +++ b/genesis/datatypes.py @@ -72,10 +72,6 @@ def _repr_brief(self): return repr_str - def __repr__(self): - if not __debug__: - self.__colorized__repr__() - def __colorized__repr__(self): repr_str = f"{colors.BLUE}{self._repr_type()}(len={colors.MINT}{formats.UNDERLINE}{len(self)}{formats.RESET}{colors.BLUE}, [" diff --git a/genesis/repr_base.py b/genesis/repr_base.py index 86f18cf..b81d0e0 100644 --- a/genesis/repr_base.py +++ b/genesis/repr_base.py @@ -1,3 +1,5 @@ +import inspect + import genesis as gs import genesis.utils.repr as ru from genesis.styles import colors, formats, styless @@ -31,9 +33,16 @@ def _repr_brief(self): repr_str += f", material: {self.material}" return repr_str + def _is_debugger(self) -> bool: + """Detect if running under a debugger (VSCode or PyCharm).""" + for frame in inspect.stack(): + if any(module in frame.filename for module in ("debugpy", "ptvsd", "pydevd")): + return True + return False + def __repr__(self): - if not __debug__: - self.__colorized__repr__() + if not self._is_debugger(): + return self.__colorized__repr__() def __colorized__repr__(self) -> str: all_attrs = self.__dir__()