Skip to content

Conversation

tleonhardt
Copy link
Contributor

@tleonhardt tleonhardt commented Sep 14, 2025

Replace codecs.open() with open() since the former is deprecated in Python 3.14

codecs.open was necessary in Python 2 because the built-in open() function could not handle different text encodings like UTF-8. It provided a way to read and write text files containing Unicode characters, which the default open() could not do without causing errors. With Python 3, the built-in open() function was changed to take an encoding argument and to handle text files as Unicode by default

Also:

  • Added uv.lock to .gitignore to make it easier to test with uv virtual environments using things like a release candidate version of Python

Closes #8446

…ython 3.14

This is to address Issue squidfunk#8446

Also:
- Added uv.lock to .gitignore to make it easier to test with uv virtual environments using things like a release candidate version of Python
@squidfunk
Copy link
Owner

Thanks for the PR. The code was adapted from @facelessuser's extension. Maybe he can shortly comment on why codecs was necessary in the first place? Does this still work in Python 3.8?

@tleonhardt
Copy link
Contributor Author

tleonhardt commented Sep 14, 2025

@squidfunk I updated the description with this text explaining that Python 2 required using codecs.open for unicode files, but in Python 3 this is supported out-of-the-box with the built-in open function:

codecs.open was necessary in Python 2 because the built-in open() function could not handle different text encodings like UTF-8. It provided a way to read and write text files containing Unicode characters, which the default open() could not do without causing errors. With Python 3, the built-in open() function was changed to take an encoding argument and to handle text files as Unicode by default

And yes this still works with I believe all versions of Python 3, certainly including 3.8.

@tleonhardt
Copy link
Contributor Author

For cmd2 that I help maintain, we had to make an identical change a couple months ago when we began testing on Python 3.14: python-cmd2/cmd2#1470

@squidfunk
Copy link
Owner

Thanks, that makes sense! Python 2, wow, that feels distant. I think this should be good to merge then.

@squidfunk squidfunk merged commit 900981b into squidfunk:master Sep 15, 2025
@tleonhardt
Copy link
Contributor Author

@squidfunk Thank you for creating and maintaining such a wonderful documentation system! I've been using it for a bit under a year now after moving to it from Sphinx and I really love it.

@facelessuser
Copy link
Contributor

I don't know exactly what MkDocs Material relies on, but I will note that codecs.open() is not exactly equivalent when using open(). open(..., errors='strict') would be equivalent. It may be that Material does not require this the "strict" parameter, but something to note that I discovered in another project where I did require strict error handling in relation to encoding, etc. Just an FYI, especially if you notice different behavior.

@squidfunk
Copy link
Owner

@facelessuser perfect, thanks for noting! If we discover problems along the way, we can add the strict parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

codecs.open DeprecationWarning when using Python 3.14
3 participants