← 返回首页
fix: replace deprecated codecs.open with built-in open (#128) by mvanhorn · Pull Request #134 · gitpython-developers/gitdb · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
Byron merged 1 commit into
gitpython-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 into
gitpython-developers:masterfrom
mvanhorn:fix/replace-codecs-open-issue-128

Conversation

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

Byron left a comment

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Thanks a lot, good catch!

Copy link
Copy Markdown
Contributor

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide 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-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.

Hide details View details Byron merged commit 53c94d6 into gitpython-developers:master Apr 30, 2026
12 checks passed
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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

codecs.open() is deprecated

3 participants

Footer

© 2026 GitHub, Inc.