Python 3.15 upgrade guide: what breaks coming from 3.13 or 3.14

Summary

Upgrading to Python 3.15 from 3.13 or 3.14 involves two distinct risks: hard removals that blow up the moment a code path executes, and silent behavior changes that a passing test suite won't flag. Grep for the removed names first (sre_parse, glob.glob1, is_reserved, load_module, CGIHTTPRequestHandler), then run tests with warnings visible to catch the loud failures like datetime.strptime rejecting %d formats without a year, NamedTuple and TypedDict losing their old call forms, ast constructors requiring all fields, sqlite3.connect making every parameter except database keyword-only, and custom loaders no longer getting load_module(). The quiet changes are the ones worth reading the changelog for: argparse now picks the single-dash long option as dest (-foo over -f), base64url decoding accepts unpadded input unless you pass padded=True, assertWarns no longer swallows unrelated warnings (which breaks under -W error), and PEP 686 makes UTF-8 the default text encoding regardless of locale. While the code is already open, run entry points with -W default::DeprecationWarning to clear 3.16 removals early, especially the asyncio event loop policy system and set_event_loop_policy, along with ~True/~False on bools, the array 'u' format code, and shutil.ExecError.

Most of what Python 3.15 removes has been printing a DeprecationWarning since 3.13, so code that already runs clean with warnings visible will mostly just work. The upgrade risk sits in two other places: a set of removals that become hard errors the moment the line executes, and a handful of behaviour changes that raise nothing at all. The second group is why it's worth reading the changelog instead of trusting a green CI run.

Python 3.15.0 was released on 9 October 2026 according to the official What's New in Python 3.15, and 3.15.2 is the newest bugfix release on the python.org downloads page. Everything shown below was run on 3.15.0. We didn't run 3.13 or 3.14 for this article, so where we describe how older versions behaved, that comes from the official docs, not from a side-by-side run.

Do you have to move now?

Not if you're on 3.13 or 3.14. The Python devguide's version table lists 3.15 and 3.14 as bugfix releases and 3.13, 3.12 and 3.11 as security-only. 3.10 reached end of life on 2026-10-01, so if you're still there, you're already running an unsupported interpreter and 3.15 is a reasonable target. 3.15 is scheduled for support until October 2031.

If you're jumping from 3.13 straight to 3.15, you pick up the 3.14 removals as well as the ones below, so read the Removed section of the 3.14 What's New too. The process is the same either way: grep for the removed names, run your tests on 3.15 with warnings visible, then go through the silent changes by hand.

Find removed APIs before they find you

A removal only fails when the code path runs, and rarely used paths (a CLI flag, a yearly report, an admin script) are exactly what test suites miss. A grep over the names in the 3.15 Removed section catches them without running anything. This is the pattern we used, run against a small sample file:

grep -rnE --include='*.py' 'sre_(compile|constants|parse)|glob\.glob[01]\(|\.is_reserved\(|CGIHTTPRequestHandler|load_module\(|co_lnotab|java_ver\(|no_type_check_decorator|NamedTuple\("[A-Za-z_]+", *[a-z_]+=|strptime\(' sample
sample/app.py:2:import sre_parse
sample/app.py:6:Point = NamedTuple("Point", x=int, y=int)
sample/app.py:10:    return [datetime.strptime(r, "%m-%d") for r in rows]
sample/app.py:14:    return glob.glob1(path, "*.sh")

The strptime( match is deliberately broad: most calls are fine, but you need to look at the format string of each one, for the reason in the next section.

Removals that fail loudly

We ran each of the main removals on 3.15.0 to see the actual error you get. The script wraps each call and prints the exception:

import sys
print(sys.version)

def attempt(label, fn):
    try:
        result = fn()
        print(f"{label}: OK -> {result!r}")
    except Exception as e:
        print(f"{label}: {type(e).__name__}: {e}")

from datetime import datetime
attempt("strptime %m-%d", lambda: datetime.strptime("02-29", "%m-%d"))
attempt("strptime with year", lambda: datetime.strptime("2028-02-29", "%Y-%m-%d").date())

from typing import NamedTuple, TypedDict
attempt("NamedTuple kwargs", lambda: NamedTuple("Point", x=int, y=int))
attempt("TypedDict no fields", lambda: TypedDict("TD"))

import ast
attempt("ast.Name()", lambda: ast.Name())

from pathlib import PureWindowsPath
attempt("is_reserved", lambda: PureWindowsPath("nul").is_reserved())

import glob
attempt("glob.glob1", lambda: glob.glob1(".", "*.py"))

attempt("import sre_compile", lambda: __import__("sre_compile"))

import sqlite3
attempt("sqlite3.connect positional", lambda: sqlite3.connect(":memory:", 5.0))
attempt("sqlite3.connect keyword", lambda: sqlite3.connect(":memory:", timeout=5.0))
3.15.0 (main, Oct  9 2026, 11:16:41) [Clang 21.0.0 (clang-2100.3.34.2)]
strptime %m-%d: ValueError: Day of month directive '%d' may not be used without a year directive. Parsing dates involving a day of month without a year is ambiguous and fails to parse leap day. Add a year to the input and format. See https://github.com/python/cpython/issues/70647.
strptime with year: OK -> datetime.date(2028, 2, 29)
NamedTuple kwargs: TypeError: NamedTuple() got an unexpected keyword argument 'x'
TypedDict no fields: TypeError: TypedDict() missing 1 required positional argument: 'fields'
ast.Name(): TypeError: ast.Name.__init__ missing 1 required positional argument: 'id'
is_reserved: AttributeError: 'PureWindowsPath' object has no attribute 'is_reserved'
glob.glob1: AttributeError: module 'glob' has no attribute 'glob1'
import sre_compile: ModuleNotFoundError: No module named 'sre_compile'
sqlite3.connect positional: TypeError: connect() takes at most 1 positional arguments (2 given)
sqlite3.connect keyword: OK -> <sqlite3.Connection object at 0x109731c40>

The strptime one is the change most likely to hit application code. When the format has no year, strptime falls back to a default year that isn't a leap year, so "02-29" could never parse. The datetime docs now make datetime.strptime raise ValueError for any %d without a year, and recommend adding a leap year yourself when the input has none:

from datetime import datetime
s = '02-29'
d = datetime.strptime(f'2000-{s}', '%Y-%m-%d')
print(d.month, d.day)
2 29

The rest have direct replacements, all named in What's New:

  • NamedTuple("Point", x=int, y=int) becomes the class syntax or the list form NamedTuple("Point", [("x", int), ("y", int)]).
  • TypedDict("TD") becomes TypedDict("TD", {}) or class TD(TypedDict): pass.
  • AST node constructors now raise TypeError when a required field is missing or an unknown keyword is passed. This only matters for code that builds AST nodes by hand.
  • PurePath.is_reserved() is gone; use os.path.isreserved().
  • glob.glob0() and glob.glob1() are gone; use glob.glob(pattern, root_dir=path).
  • The sre_compile, sre_constants and sre_parse modules are removed. Code should go through re.
  • Every sqlite3.connect() parameter except database is keyword-only, so connect(path, 5.0) must become connect(path, timeout=5.0).
  • The import system no longer calls load_module() on custom loaders (it has been deprecated in favour of exec_module() since 3.4), and zipimporter.load_module() is removed. Check any custom import hooks.
  • http.server drops CGIHTTPRequestHandler and the --cgi flag.

Changes that don't raise anything

These are the ones a passing test suite won't flag. Each is listed in the "Porting to Python 3.15" section of What's New.

argparse picks a different dest

With a short option and a single-dash long option, such as add_argument("-f", "-foo"), the attribute used to be f. The argparse docs now say the single-dash long option takes precedence, so it's foo:

import argparse
import base64

parser = argparse.ArgumentParser()
parser.add_argument("-f", "-foo")
print(parser.parse_args(["-f", "x"]))

token = "aGVsbG8"  # "hello" in base64url, padding stripped (as in a JWT)
print(base64.urlsafe_b64decode(token))
try:
    base64.urlsafe_b64decode(token, padded=True)
except Exception as e:
    print(f"padded=True: {type(e).__name__}: {e}")
Namespace(foo='x')
b'hello'
padded=True: Error: Incorrect padding

Code reading args.f now gets an AttributeError at runtime, which is at least loud. Code that does getattr(args, "f", None) or passes vars(args) along quietly loses the value. Pass dest="f" explicitly to keep the old name.

base64url no longer insists on padding

The same run shows urlsafe_b64decode() accepting unpadded input. According to the base64 docs, "Padding of input is no longer required by default", and a new padded=True argument restores the strict check. That removes the familiar "add the missing = signs" workaround for JWT segments, but if you used the padding error to reject malformed tokens, that check is gone unless you ask for it. The same docs deprecate accepting + and / in urlsafe_b64decode().

assertWarns stops swallowing other warnings

Before 3.15, a with self.assertWarns(DeprecationWarning): block silently absorbed every other warning raised inside it. The unittest docs now say warnings that don't match "are no longer swallowed". In this test the function emits a DeprecationWarning and a RuntimeWarning:

import unittest
import warnings


def old_api():
    warnings.warn("old_api() is deprecated", DeprecationWarning, stacklevel=2)
    warnings.warn("cache dir missing", RuntimeWarning, stacklevel=2)
    return 42


class T(unittest.TestCase):
    def test_old_api(self):
        with self.assertWarns(DeprecationWarning):
            self.assertEqual(old_api(), 42)
test_warns.py:14: RuntimeWarning: cache dir missing
  self.assertEqual(old_api(), 42)
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

(Python prints the script's full path in warnings; we trimmed the directory here and in the next output.) The test still passes, but the RuntimeWarning now gets through. If your CI runs with -W error or pytest's filterwarnings = error, tests that used to pass will fail on the leaked warning. That's what you want, but expect some noise on day one.

Smaller silent changes

A few more in the same category:

  • UTF-8 is now the default text encoding regardless of the system's locale (PEP 686), which changes every open() call that doesn't pass encoding. PYTHONUTF8=0 or -X utf8=0 restores the old behaviour while you add explicit encodings.
  • resource.RLIM_INFINITY is always positive now, and passing the old negative value (-1 or -3, depending on platform) to setrlimit() is deprecated.
  • An xml.etree.ElementTree.iterparse() iterator that opened a file emits a ResourceWarning if you don't close it.
  • argparse's suggest_on_error now defaults to True, which changes the error messages a CLI prints. This only matters if your tests compare that output.

The new lazy import keyword doesn't change existing code, since imports stay eager unless you opt in. If you plan to adopt it, our guide to Python 3.15 lazy imports covers the startup gains and the import errors that move to first use.

Clear the 3.16 warnings while you're there

The cheapest time to fix the next round of removals is during this upgrade, while the code is already open. Run your entry points and tests with -W default::DeprecationWarning so none of these warnings are filtered out. Here's an asyncio script that will break in 3.16:

import asyncio
from collections.abc import ByteString


async def handler():
    return "ok"


print(asyncio.iscoroutinefunction(handler))
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
print(isinstance(b"x", ByteString))
next.py:2: DeprecationWarning: 'collections.abc.ByteString' is deprecated and slated for removal in Python 3.17
  from collections.abc import ByteString
next.py:9: DeprecationWarning: 'asyncio.iscoroutinefunction' is deprecated and slated for removal in Python 3.16; use inspect.iscoroutinefunction() instead
  print(asyncio.iscoroutinefunction(handler))
next.py:10: DeprecationWarning: 'asyncio.DefaultEventLoopPolicy' is deprecated and slated for removal in Python 3.16
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
next.py:10: DeprecationWarning: 'asyncio.set_event_loop_policy' is deprecated and slated for removal in Python 3.16
  asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
next.py:11: DeprecationWarning: 'collections.abc.ByteString' is deprecated and slated for removal in Python 3.17
  print(isinstance(b"x", ByteString))
True
True

The asyncio policy system is the big one. What's New lists the whole set for removal in 3.16: AbstractEventLoopPolicy, DefaultEventLoopPolicy, both Windows policy classes, and get_event_loop_policy()/set_event_loop_policy(). Search for set_event_loop_policy across your services now; a grep finds it faster than waiting for a warning in production logs. The same list includes ~True and ~False on bools, the array 'u' format code, and shutil.ExecError. The profile module is slated for 3.17 in favour of the new profiling.tracing.

PYTHON 3.15 PYTHON UPGRADE DEPRECATION ARGPARSE ASYNCIO UNITTEST

  RELATED

  COMMENTS

0

No comment for this article.