Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 11, 2024 10:18
Show Gist options
  • Save mypy-play/896b3c93cfd8a39cba0839c43650e9c9 to your computer and use it in GitHub Desktop.
Save mypy-play/896b3c93cfd8a39cba0839c43650e9c9 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from collections.abc import Callable
def pprint(obj: object, repr_fn: Callable[..., str] = NotImplemented):
repr_fn = (
repr_fn # expression has type "function", variable has type "Callable[..., str]"
if repr_fn is not NotImplemented
else repr
)
return repr_fn(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment