{"id":16221531,"url":"https://github.com/hrbigelow/pyctb","last_synced_at":"2026-05-07T19:15:54.375Z","repository":{"id":63655043,"uuid":"569576831","full_name":"hrbigelow/pyctb","owner":"hrbigelow","description":"Python Customized Tracebacks","archived":false,"fork":false,"pushed_at":"2022-12-06T21:18:16.000Z","size":28,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-12T00:06:45.953Z","etag":null,"topics":["debugging-tool","pytorch","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbigelow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-23T06:22:09.000Z","updated_at":"2023-02-11T04:52:56.000Z","dependencies_parsed_at":"2023-01-23T12:50:13.750Z","dependency_job_id":null,"html_url":"https://github.com/hrbigelow/pyctb","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hrbigelow/pyctb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbigelow%2Fpyctb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbigelow%2Fpyctb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbigelow%2Fpyctb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbigelow%2Fpyctb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbigelow","download_url":"https://codeload.github.com/hrbigelow/pyctb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbigelow%2Fpyctb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271437616,"owners_count":24759630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugging-tool","pytorch","tensorflow"],"created_at":"2024-10-10T12:08:34.575Z","updated_at":"2025-10-26T23:11:26.228Z","avatar_url":"https://github.com/hrbigelow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Customized Tracebacks\n\n## Installation\n\n```\npip install pyctb \n```\n\n## Synopsis\n\n```python\nimport pyctb\n\n# add a pre-existing group of custom rendering functions\npyctb.add_group('torch')\n\n# or add your own:\n# pyctb.add(your_cls, your_render_func)\n# pyctb.add(your_cls2, your_render_func2)\n# ...\n\n# for each frame in the traceback:\n# display 1 piece of code context before the current executing piece\n# display 0 pieces of code context after the current executing piece\npyctb.config(before_ctx=1, after_ctx=0)\n\n# activate the custom tracebacks\npyctb.on()\n\n# your program code below.  any exception will generate a customized traceback\n...\n\n# exceptions will now generate the default traceback as before\npyctb.off()\n```\n\n## Introduction\n\npyctb is tool for customizing the information displayed in a Python traceback.\nIt is useful to quickly see the values of arguments or operands used at the\npoint where your program throws an exception, without the need for a debugger.\nFor each traceback frame, pyctb adds extra lines of the form `var =\nrender_func(value)` for each variable in the currently executing function of\nthat frame, using a `render_func` registered with that class.  By default,\n`object` is registered to use `repr`.  The user may register custom functions for\nrendering specific types of their choice.  Such specific rendering functions\nare needed for types that have too large of an output with just `repr`.\n\npyctb relies on the excellent\n[stack_data](https://github.com/alexmojaki/stack_data) repo from Alex Hall for\ninspecting the frame information variable names and values.\n\nYou may register a new rendering function using:\n\n`pyctb.add(cls, func)`\n\nObjects are rendered using the most specific (in method-resolution order)\nrendering function registered.  For example:\n\n```python\npyctb.add(Animal, render_animal)\npyctb.add(Cat, render_cat)\npyctb.add(Tabby, render_tabby)\n```\n\nThen, a `Tabby` will be rendered with `render_tabby`.  A `Persian` will use\n`render_cat`, and `Dog` will use `render_animal`, and so forth.  By default,\n`object` is registered with `repr`.\n\n## Tests\n\n```bash\n# compare default and customized tracebacks using the `torch` group of\n# renderers.  In each frame of the traceback, \u003cbefore_ctx\u003e and \u003cafter_ctx\u003e\n# specify the number of pieces of code context to be displayed before and after\n# each currently executing piece.  Using 0 for both \u003cbefore_ctx\u003e and\n# \u003cafter_ctx\u003e is equivalent to the default behavior.\npython -m tests.torch_test \u003cbefore_ctx\u003e \u003cafter_ctx\u003e\n\n# same but with tensorflow tests.\npython -m tests.tf_test \u003cbefore_ctx\u003e \u003cafter_ctx\u003e\n```\n\nThe `tests.torch_test` runs two functions called `binop_test` and\n`matmul_test`.  Each function raises an exception, and it is run twice.  First\nwith `pyctb` turned off, and then with it turned on.  The default and custom\ntracebacks are shown as output.\n\nNotice that the custom traceback provides additional `name = value` lines for\nall arguments to the function or operand that raised the exception.  In this\ncase, using the `torch` group, the operands were `torch.Tensor`, and the custom\nrendering function displays them in a format `shape:dtype:device`.\n\nAdditionally, you can see that there is one piece of leading code context (if\nit exists in that frame) shown before the currently executing piece.\n\n```\n# Run the torch_tests using 1 piece of leading context and non trailing context\n(pytorch181) henry@henry-gs65:pyctb$ python -m tests.torch_test 1 0\n========= Default traceback for binop_test =========\nTraceback (most recent call last):\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 25, in main\n    test()\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 16, in binop_test\n    return a / b\nRuntimeError: The size of tensor a (5) must match the size of tensor b (6) at non-singleton dimension 1\n\n\n========= Custom traceback for binop_test =========\n1 pieces of leading context\n0 pieces of trailing context\nCustom Traceback (most recent call last):\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 34, in main\n    try:\n--\u003e     test()\n         test = \u003cfunction binop_test at 0x7f86bbfeda60\u003e\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 16, in binop_test\n    b = torch.randn(3,6,7)\n--\u003e return a / b\n         a = [3,5,7]:float32:cpu\n         b = [3,6,7]:float32:cpu\nRuntimeError: The size of tensor a (5) must match the size of tensor b (6) at non-singleton dimension 1\n\n\n========= Default traceback for matmul_test =========\nTraceback (most recent call last):\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 25, in main\n    test()\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 9, in matmul_test\n    d = torch.matmul(a, b)\nRuntimeError: Expected batch2_sizes[0] == bs \u0026\u0026 batch2_sizes[1] == contraction_size to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.)\n\n\n========= Custom traceback for matmul_test =========\n1 pieces of leading context\n0 pieces of trailing context\nCustom Traceback (most recent call last):\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 34, in main\n    try:\n--\u003e     test()\n         test = \u003cfunction matmul_test at 0x7f87e7ce8c10\u003e\n  File \"/home/henry/ai/projects/pyctb/tests/torch_test.py\", line 9, in matmul_test\n    c = b * 5\n--\u003e d = torch.matmul(a, b)\n         a = [3,5,7]:float32:cpu\n         b = [3,5,7]:float32:cpu\nRuntimeError: Expected batch2_sizes[0] == bs \u0026\u0026 batch2_sizes[1] == contraction_size to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.)\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbigelow%2Fpyctb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbigelow%2Fpyctb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbigelow%2Fpyctb/lists"}