Skip to content

Commit f0c4a95

Browse files
committed
Add mypy type checking for Python 3.14 and use open() instead of codecs.open() due to deprecation in 3.14
The first release candidate for Python 3.14 was released on 2025-07-22 and I did some local testing. The first thing I realized is that mypy now works well with 3.14 and so we should add type checking on that platform to our GitLab Actions. The second thing I noticed is that when we ran tests with pytests, we were getting a bunch of warnings due to `codecs.open()` being deprecated. Since at least Python 3.6 there has been no need for that as `open()` does everything it can do plus more.
1 parent 37c03c5 commit f0c4a95

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

.github/workflows/typecheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
18+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
1919
fail-fast: false
2020
defaults:
2121
run:

cmd2/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,12 @@ def is_text_file(file_path: str) -> bool:
183183
:return: True if the file is a non-empty text file, otherwise False
184184
:raises OSError: if file can't be read
185185
"""
186-
import codecs
187-
188186
expanded_path = os.path.abspath(os.path.expanduser(file_path.strip()))
189187
valid_text_file = False
190188

191189
# Only need to check for utf-8 compliance since that covers ASCII, too
192190
try:
193-
with codecs.open(expanded_path, encoding='utf-8', errors='strict') as f:
191+
with open(expanded_path, encoding='utf-8', errors='strict') as f:
194192
# Make sure the file has only utf-8 text and is not empty
195193
if sum(1 for _ in f) > 0:
196194
valid_text_file = True

0 commit comments

Comments
 (0)