Proposal: Drop the traceback from the module-level backend error objects.#112
Merged
cpburnz merged 1 commit intocpburnz:masterfrom Mar 18, 2026
Merged
Proposal: Drop the traceback from the module-level backend error objects.#112cpburnz merged 1 commit intocpburnz:masterfrom
cpburnz merged 1 commit intocpburnz:masterfrom
Conversation
Owner
|
It is obscure, but there's no strong benefit of keeping the original traceback. This is with the original traceback: >>> pathspec.PathSpec.from_lines('gitignore', [], backend='re2')
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
pathspec.PathSpec.from_lines('gitignore', [], backend='re2')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/pathspec.py", line 261, in from_lines
return cls(patterns, backend=backend, _test_backend_factory=_test_backend_factory)
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/pathspec.py", line 82, in __init__
use_backend = self._make_backend(backend, patterns)
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/pathspec.py", line 281, in _make_backend
return make_pathspec_backend(name, patterns)
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/_backends/agg.py", line 100, in make_pathspec_backend
return Re2PsBackend(cast(Sequence[RegexPattern], patterns))
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/_backends/re2/pathspec.py", line 58, in __init__
raise re2_error
File "/home/caleb/Downloads/venv/lib/python3.14/site-packages/pathspec/_backends/re2/_base.py", line 17, in <module>
import re2
ModuleNotFoundError: No module named 're2'And this is using your change to remove the original traceback: >>> pathspe.PathSpec.from_lines('gitignore', [], backend='re2')
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
pathspec.PathSpec.from_lines('gitignore', [], backend='re2')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 267, in from_lines
return cls(patterns, backend=backend, _test_backend_factory=_test_backend_factory)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 82, in __init__
use_backend = self._make_backend(backend, patterns)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 287, in _make_backend
return make_pathspec_backend(name, patterns)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/_backends/agg.py", line 100, in make_pathspec_backend
return Re2PsBackend(cast(Sequence[RegexPattern], patterns))
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/_backends/re2/pathspec.py", line 58, in __init__
raise re2_error
ModuleNotFoundError: No module named 're2'I don't think keeping the original traceback adds any important information, particularly because the exception remains a clear >>> pathspec.PathSpec.from_lines('gitignore', [], backend='re2')
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
pathspec.PathSpec.from_lines('gitignore', [], backend='re2')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 267, in from_lines
return cls(patterns, backend=backend, _test_backend_factory=_test_backend_factory)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 82, in __init__
use_backend = self._make_backend(backend, patterns)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/pathspec.py", line 287, in _make_backend
return make_pathspec_backend(name, patterns)
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/_backends/agg.py", line 100, in make_pathspec_backend
return Re2PsBackend(cast(Sequence[RegexPattern], patterns))
File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/_backends/re2/pathspec.py", line 58, in __init__
raise re2_error
AttributeError: module 're2' has no attribute 'Options'with this missing: File "/home/caleb/Personal/Projects/python/python-pathspec/pathspec/_backends/re2/_base.py", line 27, in <module>
RE2_OPTIONS = re2.Options()
^^^^^^^^^^^Thanks. |
Contributor
Author
|
Thank you for taking a close look at the tracebacks and merging my PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why? These are module-level objects that will live forever. Normally this is fine. But if we lazily import
pathspecin somewhere deep in the Python program (or with the upcoming PEP 810 explicit lazy import in Python 3.15), it will hold the traceback, thus the locals of each frame, in memory forever.We ran into such case where we might hold GBs of memory because of this edge case.
As far as I can tell, we don't really need the traceback on the exception object here.
What do you think? I can totally understand this seems to be out of the blue optimization for super rare edge cases.
Thanks for your consideration in advance!