Registry / testing / traceback2

traceback2

JSON →
library1.4.0pypypi✓ verified 24d ago

Traceback2 is a Python library that provides a backport of the standard library's `traceback` module to older supported Python versions. Its primary goal was to offer modern traceback formatting and functionality to environments where the native `traceback` module lacked these features. The current version is 1.4.0, released in March 2015, indicating a very slow release cadence and minimal, if any, active development for new features or modern Python versions.

pip install traceback2
INSTALL
IMPORT
SIG · TRACEBACK2
T
traceback2
testingpythonv1.4.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

traceback
import traceback2
from traceback2 import traceback

This quickstart demonstrates how to import `traceback2` and use its `print_exc` function within an exception handler to print the current exception's traceback. It is typically aliased as `traceback` to match the standard library module it backports.

import traceback2 as traceback def problematic_function(): raise ValueError("Something went wrong in the function!") try: problematic_function() except ValueError as e: print(f"Caught an exception: {e}") print("\n--- Traceback (formatted by traceback2) ---") traceback.print_exc()
Debug
Known issues
gotchaTraceback2 is a backport primarily for older Python versions (e.g., Python 2.x). For modern Python 3.x installations, the built-in `traceback` module provides all equivalent functionality and should be used instead.
fix
For Python 3.x, use `import traceback` directly. Only install and use `traceback2` if targeting specific older Python environments that lack the desired traceback features.
affects: < 1.4.0 (for Python 3.x users, implicitly)
gotchaWhen used in Python 2.x, `traceback2` produces unicode output, which differs from the standard library `traceback` module's byte string output in Python 2. This behavior is due to its dependency on `linecache2`.
fix
Be aware of potential encoding issues or unexpected string types if your Python 2.x application expects byte strings from traceback output.
affects: 1.x (Python 2.x environments)
gotchaException frame clearing (a feature for memory management by breaking reference cycles) might silently do nothing if the underlying Python interpreter does not support it.
fix
Do not rely on frame clearing from `traceback2` for critical memory management, especially in older or non-standard Python interpreters. Verify its effect if it's a critical component of your memory strategy.
affects: All versions, depending on Python interpreter
deprecatedThe `traceback2._some_str` (an unofficial API) behaves like the Python 3 version: objects where `unicode(obj)` fails but `str(obj)` works will be shown as `b'thestrvaluerepr'`. Relying on this internal API is not recommended and its behavior could be considered a breaking change if an application implicitly depended on Python 2's `_some_str` behavior.
fix
Avoid using internal, unofficial APIs like `_some_str`. If similar functionality is needed, implement it explicitly or find a stable public API.
affects: 1.x (Python 2.x environments)
gotchaThe library is not actively maintained, with the last release (1.4.0) being from March 2015. This means there will be no updates for new Python features, bug fixes, or security patches. It also dropped support for Python 2.6 and 3.2.
fix
For new development, strongly prefer the standard library `traceback` module. `traceback2` should only be used in legacy projects requiring its specific backported functionality on older Python runtimes where the standard library is insufficient.
affects: All versions (for new projects)
Upgrade
Version history
1.4.0latest on PyPI · released Mar 9, 2015
Audit
Dependencies
linecache2requiredUsed to produce unicode output in Python 2.x environments.
Agent activity
26 hits · last 30 days
node
24
Resources