What Changes in Python 3.15 and What Does Not
Python 3.15 enables UTF-8 mode by default, a change defined by PEP 686 that affects text operations relying on an implicit encoding. It is not an automatic document conversion: an old CSV retains the same bytes after updating the interpreter. What may vary is the interpretation of those bytes when a program opens the file without specifying its encoding.
The Python 3.15 What’s New documentation places the series release on October 9, 2026. Python 3.15.1 was published on October 21 as the first maintenance release. To follow this tutorial, you only need a 3.15 series interpreter from a trusted distribution and a separate test folder. No additional libraries are required for the encoding examples.
The benefit of the new default is reducing an environment dependency that could go unnoticed. If a project already declares its encodings and works with UTF-8 end-to-end, it may not observe differences in those files. If it exchanges old documents with other applications, reviewing the input/output contract is advisable. Updating Python and changing a file format are distinct operations.
First Identify Your Interpreter and Mode
Run the diagnosis with the same interpreter the project will use, not another Python that appears earlier in the system path. On macOS or Linux, it can be invoked as python3.15; on Windows, use the corresponding manager or launcher, for example py -3.15 if that installation is registered. Available names depend on how Python was installed. Replace python in the examples if your system requires another command.
import locale
import sys
print(sys.version)
print(sys.executable)
print(sys.flags.utf8_mode)
print(locale.getencoding())
sys.flags.utf8_mode indicates the mode status. locale.getencoding() queries the regional encoding and may yield a different result: PEP 686 explains precisely that separation. Do not infer a file’s encoding from this diagnosis. The program may be in UTF-8 mode and still receive a document generated in another encoding.
Locate Reads and Writes Relying on Implicit Values
Review operations that open text without encoding, especially importers, exporters, scheduled tasks, and utilities exchanging documents. The key point is not to add the same label everywhere, but to make the expected format explicit at each boundary. A proprietary config file and an export from an old system may require different decisions, even if both end with the .txt extension.
The -X warn_default_encoding option allows requesting warnings about uses relying on the default encoding. You can run python -X warn_default_encoding your_program.py in a test environment and review the warnings alongside the code paths you actually process. A warning guides the review, it does not prove data corruption. Similarly, seeing no warnings does not replace testing relevant inputs: there may be program paths that have not been executed.
| Situation | Recommended Decision | Verification |
|---|---|---|
| File format requires UTF-8 | Declare encoding="utf-8" |
Read and write with non-ASCII characters |
| Legacy file documented as CP1252 | Declare encoding="cp1252" |
Compare decoded text with expected original |
| Binary data | Use binary mode when appropriate | Do not treat as text based on extension |
| Unknown format | Identify origin before converting | Avoid overwriting the only original |
A Small Test Showing the Problem Without Touching Your Documents
Create a Sample Legacy File
This example generates a disposable CP1252 document, verifies that reading it as UTF-8 produces an error, and re-reads it with the correct encoding. The temporary folder is deleted upon completion. It does not run the test against your working files nor require replacing a Python installation.
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as folder:
file = Path(folder) / "legacy.txt"
expected = "café: 20 €"
file.write_bytes(expected.encode("cp1252"))
try:
file.read_text(encoding="utf-8")
except UnicodeDecodeError:
print("UTF-8 does not match this file")
actual = file.read_text(encoding="cp1252")
assert actual == expected
The exception is deliberate: it allows observing a mismatch between bytes and encoding, not a random hardware failure. A test with ASCII letters would have hidden this case because many formats share those values. Include accents, symbols, and representative examples of the documents your project uses.
Convert Only After Reading Correctly
Once the source encoding is known, you can write a UTF-8 copy by also specifying the destination encoding. Keep the original and verify the resulting text before replacing it. Decoding without raising an exception does not guarantee by itself that everything is correct: a wrong interpretation can produce plausible but erroneous characters. The criterion should be the expected content, not just the absence of errors.
How to Compare Behavior and When to Use a Temporary Workaround
Documentation allows disabling the mode at startup with python -X utf8=0 your_program.py or the PYTHONUTF8=0 variable for that process. It serves to compare behavior while locating implicit dependencies. It does not convert documents, does not modify their actual encoding, and does not mean any environment switches to CP1252: the result depends on its regional settings.
Avoid turning that temporary workaround into a permanent fix without understanding what makes it necessary. The most predictable approach is usually declaring the file format in the code that reads or writes it. Do not use errors="ignore" to make a migration problem disappear: it can remove characters and allow a flow to finish apparently well with incomplete information. If a format supports a recovery policy, it must be defined and checked explicitly.
A Repeatable Migration Check
Prepare a small set of representative files and run the same tests with the previous interpreter and with 3.15. Include reading, transformation, and writing, not just application startup. For each case, keep the expected text and, when the format requires it, also check the produced bytes. This helps distinguish an encoding change from another compatibility issue that appears when updating dependencies or tools.
Before changing a real service, verify which executable the scheduled task uses, which environment variables it receives, and where it stores its results. Keep a recoverable copy of the data and a way to revert to the previous environment. A reproducible test is worth more than checking a single document manually. The goal of the migration is for each file’s contract to be clear and stable, not for the program to tolerate any input at the cost of hiding differences.