Skip to content

DeprecationWarning: codecs.open() is deprecated in Python 3.13+ #126

@Vallhalen

Description

@Vallhalen

Description

When running tests with Python 3.12+, the library emits deprecation warnings about codecs.open():

DeprecationWarning: 'codecs.open' is deprecated. Use built-in open() instead.

This appears to come from the internal file loading mechanism.

Environment

  • Python: 3.12+
  • python-frontmatter: 1.1.0

Suggested Fix

Replace codecs.open() with the built-in open() function with explicit encoding parameter:

# Before
import codecs
with codecs.open(path, 'r', encoding='utf-8') as f:
    content = f.read()

# After
with open(path, 'r', encoding='utf-8') as f:
    content = f.read()

The built-in open() has supported the encoding parameter since Python 3.0, so this change would be backwards compatible.

Workaround

Currently filtering the warning in pytest.ini:

filterwarnings =
    ignore::DeprecationWarning:frontmatter.*:

Thank you for maintaining this library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions