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.
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.