Skip to content

Instantly share code, notes, and snippets.

@waszil
waszil / hide_traceback.py
Created July 8, 2020 07:46
Disable traceback printing temporarily in python
from contextlib import contextmanager
@contextmanager
def hide_traceback() -> None:
def is_running_from_ipython() -> bool:
""" Checks whether running in IPython interactive console or not """
try:
import IPython
except ImportError:
@waszil
waszil / attrs_lazy_loading.py
Last active December 4, 2021 21:55
Lazy loading attributes with python attrs
"""
Example for creating classes with attrs that contain lazy-loaded fields.
"""
import attr
_lazy_fields_container_name = "_lazy_fields"
_lazy_field_metadata_key = "lazy"
_lazy_loader_function_prefix = "lazy_loader__"