QuestionPython 3.15 is out: what is "lazy import" and will UTF-8 by default break my scripts?

SL Sara L. Member Joined: Jul 17, 2026
Posts: 80
#1

Saw that 3.15 came out on 09.10 (https://docs.python.org/3.15/whatsnew/3.15.html). Two things in the notes I don't fully get: lazy import (PEP 810) and UTF-8 becoming the default (PEP 686). I have a bunch of little scripts on a Windows laptop that read and write text files. Anything to worry about?

KW Kate W. Member Joined: Sep 4, 2026
Posts: 20
#2

The UTF-8 one is the change that matters for you. Until now open() without an encoding argument used the system's locale encoding, which on Windows is often not UTF-8. With 3.15, UTF-8 mode is on by default, so those calls read and write UTF-8 everywhere.

If your old files were written in a Windows code page, reading them may now fail or show garbage. The clean fix is to say what you mean:

with open("old_notes.txt", encoding="cp1252") as f:
    text = f.read()

with open("report.csv", "w", encoding="utf-8", newline="") as f:
    f.write(text)

PEP 686 still lets you switch the mode off with PYTHONUTF8=0, but that's a stopgap rather than a fix.

IS Irakli S. Member Joined: Sep 18, 2026
Posts: 44
#3

And lazy import: the module is loaded not at the import line but the first time you actually use the name. Handy for command-line tools where most runs never touch a heavy library:

lazy import json
lazy from decimal import Decimal

def main() -> None:
    print("fast start")  # json and decimal are not loaded yet

def export(data: dict) -> str:
    return json.dumps(data)  # json is loaded here, on first use

It is a module-level statement, so for small scripts you won't notice much difference. Code that relies on side effects of importing a module (registering plugins, for example) should keep the normal import.

SL Sara L. Member Joined: Jul 17, 2026
Posts: 80
#4

Thanks both! Last one: a couple of the scripts still run on 3.10. Worth jumping straight to 3.15 or go step by step?

TP Tomasz P. Member Joined: Jun 30, 2026
Posts: 84
#5

3.10 is end of life since October 2026, so no more security fixes. I think one jump is fine for small scripts, but test each script after.

KW Kate W. Member Joined: Sep 4, 2026
Posts: 20
#6

>>5
Agreed. Make a fresh virtual environment with 3.15, reinstall the packages there and run each script once. The bigger jump is usually in the third-party packages, not in your own code, so check they all install on 3.15 first.

Quick reply

Only signed-in members can write. Sign in