micropython / micropython/micropython

namedtuple does not support "defaults" keyword argument

Open
#14,303 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement py-core
Dominant language
C
Stars
22.1k
Forks
9k
Avg merge
6d 4h
Merged PRs (30d)
16

Description

Checks
  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues matching this bug, and didn't find any.

Port, board and/or hardware

Pico W (RP2040)

MicroPython version

MicroPython v1.22.2 on 2024-02-22; Raspberry Pi Pico W with RP2040

Reproduction
>>> from collections import namedtuple
>>> namedtuple('a', ['a'], defaults=[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function doesn't take keyword arguments
Expected behaviour

Expected the creation of a NamedTuple with defaults.

Observed behaviour

Exception as shown in repro code.

Additional Information

The keyword-only argument of defaults was added in Python 3.7 according to the Python docs. I could not find any mention of this change or disparity in the MicroPython docs.

I did, however, find that the change to other arguments becoming keyword-only in Python 3.6 is not listed as implemented in the MicroPython docs.

It seems like the lack of keyword argument support might be intentional - I'm not sure if this means it should be considered a feature request and/or docs improvement instead?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the collections.namedtuple call on the reported Pico W and compare its behavior with the Python 3.7 documentation. Trace the namedtuple entry point to determine whether defaults support is intended; done means the behavior is either supported with coverage or the MicroPython divergence is explicitly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.