Python: fix TypeError: NamedTuple() got an unexpected keyword argument 0 ▲ Adam Johnson 1 hour ago · Tech · hide · 0 comments Take this code, defining a small NamedTuple with a keyword argument per field: from typing import NamedTuple Point = NamedTuple("Point", x=int, y=int) Run it on Python 3.13 or 3.14, and you’ll see: $ python3.14 example.py /.../example.py:3: DeprecationWarning: Creating NamedTuple classes using keyword arguments is deprecated and will be disallowed in Python 3.15. Use the class-based or functional syntax instead. Point = NamedTuple("Point", x=int, y=int) And on Python 3.15+, it’s broken: $ python3.15 example.py Traceback (most recent call last): ... TypeError: NamedTuple() got an unexpected keyword argument 'x' What’s up with that? NamedTuple has always had two documented ways to define fields: the class-based syntax, and a functional syntax taking a list of (name, type) pairs. The keyword-argument style above was never one of them, it worked only as a side effect of the old implementation happening to accept **kwargs. This form was therefore deprecated and removed in Python 3.15, with… No comments yet. Log in to reply on the Fediverse. Comments will appear here.