Skip to content

Instantly share code, notes, and snippets.

@brandonwillard
Created July 22, 2021 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonwillard/4e4550cbbea96b83b38f40bcf5824d16 to your computer and use it in GitHub Desktop.
Save brandonwillard/4e4550cbbea96b83b38f40bcf5824d16 to your computer and use it in GitHub Desktop.
A `.pdbrc` file with custom `pdb` commands
#
# XXX: This .pdbrc is only valid for Python > 3.x
#
import os
import pdb
from pprint import pprint as __pprint
from contextlib import suppress as __suppress
# Use IPython's pretty printing within PDB
with __suppress(ImportError): from IPython.lib.pretty import pprint as __pprint
pdb.__pprint = __pprint
alias pp import pdb; pdb.__pprint(%*)
# Aesara debugging
# This will automatically enable the "print test values" option in Aesara
exec("if os.environ.get(\"AESARA_PDB\", False):\n\twith __suppress(ImportError): from aesara import config as __config; __config.print_test_value = True")
# Print a dictionary sorted by key.
alias pd pp {k: v for k, v in sorted(dict(%*).items(), key=lambda i: i[0])}
# Print the member variables of a thing.
alias pi pd %*.__dict__
alias pdir pp dir(%*)
alias pii import inspect as __inspect;; pd dict(__inspect.getmembers(%1))
# Print the member variables of self.
alias ps pi self
# Print the locals.
alias pl pd locals()
alias pg pd globals()
# Next and list, and step and list.
alias nll n;;ll
alias nl n;;l
alias sl s;;l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment