Skip to content

fix: replace deprecated codecs.open with built-in open (#128)#134

Merged
Byron merged 1 commit intogitpython-developers:masterfrom
mvanhorn:fix/replace-codecs-open-issue-128
Apr 30, 2026
Merged

fix: replace deprecated codecs.open with built-in open (#128)#134
Byron merged 1 commit intogitpython-developers:masterfrom
mvanhorn:fix/replace-codecs-open-issue-128

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Fixes #128.

What changed

gitdb/db/ref.py:45 used codecs.open(self._ref_file, 'r', encoding="utf-8"). Replaced it with the built-in open(self._ref_file, 'r', encoding="utf-8") and dropped the now-unused import codecs.

Why this matters

Running the test suite under Python 3.14 emits the warning quoted in the issue:

gitdb/db/ref.py:45: DeprecationWarning: codecs.open() is deprecated. Use open() instead.
  with codecs.open(self._ref_file, 'r', encoding="utf-8") as f:

The built-in open() has accepted the encoding keyword since Python 3.0, and the call site already passed encoding="utf-8", so the replacement is byte-for-byte equivalent on every supported Python version. @Byron's comment on the issue ("if using open in 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 passed
  • grep -rn 'codecs.open' --include='*.py' — 0 matches after the change

…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
@Byron Byron requested a review from Copilot April 30, 2026 10:13
Copy link
Copy Markdown
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, good catch!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-in open(..., encoding="utf-8") in _update_dbs_from_ref_file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Byron Byron merged commit 53c94d6 into gitpython-developers:master Apr 30, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

codecs.open() is deprecated

3 participants