fix: replace deprecated codecs.open with built-in open (#128)#134
Merged
Byron merged 1 commit intogitpython-developers:masterfrom Apr 30, 2026
Merged
Conversation
…elopers#128) Python 3.14 emits a DeprecationWarning for codecs.open(), which gitdb hits inside ReferenceDB._update_dbs_from_ref_file: DeprecationWarning: codecs.open() is deprecated. Use open() instead. The built-in open() has supported the encoding kwarg since Python 3.0 and the call site already passes encoding="utf-8", so the replacement is byte-for-byte equivalent on every supported Python version. Dropped the now-unused codecs import. Verified the change with the existing test_ref.py suite. Closes gitpython-developers#128
There was a problem hiding this comment.
Pull request overview
This PR addresses Python 3.14 deprecation warnings by replacing usage of codecs.open() with the built-in open() when reading the reference file for ReferenceDB.
Changes:
- Remove the unused
import codecs. - Replace
codecs.open(..., encoding="utf-8")with built-inopen(..., encoding="utf-8")in_update_dbs_from_ref_file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #128.
What changed
gitdb/db/ref.py:45usedcodecs.open(self._ref_file, 'r', encoding="utf-8"). Replaced it with the built-inopen(self._ref_file, 'r', encoding="utf-8")and dropped the now-unusedimport codecs.Why this matters
Running the test suite under Python 3.14 emits the warning quoted in the issue:
The built-in
open()has accepted theencodingkeyword since Python 3.0, and the call site already passedencoding="utf-8", so the replacement is byte-for-byte equivalent on every supported Python version. @Byron's comment on the issue ("if usingopenin its place is backwards compatible within the v3 version of python, this should be an easy fix") is exactly what this is.Verification
pytest gitdb/test/db/test_ref.py— 1 passedgrep -rn 'codecs.open' --include='*.py'— 0 matches after the change