---
title: "Python: fix TypeError: NamedTuple() got an unexpected keyword argument"
url: https://daily.dev/posts/python-fix-typeerror-namedtuple-got-an-unexpected-keyword-argument-hhcfokoyo
source_url: https://adamj.eu/tech/2026/08/13/python-fix-typeerror-namedtuple-got-an-unexpected-keyword-argument
type: article
source: "Adam Johnson"
published: 2026-08-13T20:02:02.751Z
updated: 2026-08-13T20:11:12.219Z
tags: ["python"]
reading_time: 3
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Python: fix TypeError: NamedTuple() got an unexpected keyword argument

**[Adam Johnson](https://daily.dev/sources/adamj)** · 3 min read · 0 upvotes · 0 comments

## Summary

Defining a NamedTuple using keyword arguments (e.g., NamedTuple("Point", x=int, y=int)) was never officially documented syntax, only worked as a side effect of the old implementation accepting **kwargs. This form is deprecated on Python 3.13/3.14 and raises TypeError on Python 3.15+ since NamedTuple's signature is now positional-only. Fix by switching to class-based syntax or the documented functional syntax with a list of (name, type) tuples. Ruff's UP014 rule auto-fixes both forms to class syntax, and as of Ruff 0.16 (released July 2026) this rule is enabled by default.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://adamj.eu/tech/2026/08/13/python-fix-typeerror-namedtuple-got-an-unexpected-keyword-argument>

## Questions this post answers

### Why do I get TypeError: NamedTuple() got an unexpected keyword argument in Python 3.15?

Python 3.15 removes support for the undocumented keyword-argument syntax for creating NamedTuple classes, such as NamedTuple("Point", x=int, y=int). This style only ever worked as a side effect of the old implementation accepting **kwargs and was never officially documented; it was deprecated in Python 3.13/3.14 and is now disallowed, with NamedTuple's signature locked to positional-only.

_daily.dev surfaces breaking changes like this so python upgrades don't stall on runtime errors._

### How do I fix code that defines a NamedTuple with keyword arguments after upgrading Python?

Switch to class-based syntax, defining a class that inherits from NamedTuple with typed attributes, or use the documented functional syntax with a list of (name, type) tuples like NamedTuple("Point", [("x", int), ("y", int)]). Both are supported alternatives to the removed keyword-argument form in Python 3.15.

_Developers modernizing python code can track fixes like this through daily.dev._

### Can Ruff automatically fix the deprecated NamedTuple keyword argument syntax?

Yes, Ruff's pyupgrade-derived rule convert-named-tuple-functional-to-class (UP014) rewrites both the list-of-tuples functional form and the keyword-argument form into class-based syntax automatically. As of Ruff 0.16, released July 2026, UP014 is enabled by default, so running ruff check --fix handles it without extra configuration; older Ruff versions need --select UP014 or --select UP.

_daily.dev helps developers keep up with linting rule changes like Ruff's default rule set._

## Similar posts on daily.dev

- [Python 3.14 Preview: Better Syntax Error Messages – Real Python](https://daily.dev/posts/python-3-14-preview-better-syntax-error-messages-real-python-7mcpknwe6) · Real Python · 39 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/python-fix-typeerror-namedtuple-got-an-unexpected-keyword-argument-hhcfokoyo)
