arduino/Arduino · error · TypeError

expected at most 1 arguments, got %d

Error message

expected at most 1 arguments, got %d

What it means

This pure-Python OrderedDict backport mirrors CPython's dict/OrderedDict constructor signature: it accepts at most one positional argument (an iterable of key/value pairs). If __init__ receives more than one positional argument it raises TypeError('expected at most 1 arguments, got N'), matching the error a regular dict would raise.

Source

Thrown at arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/packages/ordered_dict.py:36

    'Dictionary that remembers insertion order'
    # An inherited dict maps keys to values.
    # The inherited dict provides __getitem__, __len__, __contains__, and get.
    # The remaining methods are order-aware.
    # Big-O running times for all methods are the same as for regular dictionaries.

    # The internal self.__map dictionary maps keys to links in a doubly linked list.
    # The circular doubly linked list starts and ends with a sentinel element.
    # The sentinel element never gets deleted (this simplifies the algorithm).
    # Each link is stored as a list of length three:  [PREV, NEXT, KEY].

    def __init__(self, *args, **kwds):
        '''Initialize an ordered dictionary.  Signature is the same as for
        regular dictionaries, but keyword arguments are not recommended
        because their insertion order is arbitrary.

        '''
        if len(args) > 1:
            raise TypeError('expected at most 1 arguments, got %d' % len(args))
        try:
            self.__root
        except AttributeError:
            self.__root = root = []                     # sentinel node
            root[:] = [root, root, None]
            self.__map = {}
        self.__update(*args, **kwds)

    def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
        'od.__setitem__(i, y) <==> od[i]=y'
        # Setting a new item creates a new link which goes at the end of the linked
        # list, and the inherited dictionary is updated with the new key/value pair.
        if key not in self:
            root = self.__root
            last = root[0]
            last[1] = root[0] = self.__map[key] = [last, root, key]
        dict_setitem(self, key, value)

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Merge the inputs into one iterable first: pass a single list of pairs, e.g. OrderedDict(list(d1.items()) + list(d2.items())).
  2. Use keyword arguments plus a single positional: OrderedDict(d1, **d2) is still one positional argument and is accepted.
  3. Create empty OrderedDict then update: od = OrderedDict(); od.update(d1); od.update(d2).
  4. On Python 3, prefer collections.OrderedDict or dict | merge syntax instead of the vendored backport.

Example fix

// before
od = OrderedDict(headers, extra_headers)  # TypeError: expected at most 1 arguments, got 2
// after
od = OrderedDict(list(headers.items()) + list(extra_headers.items()))
Defensive patterns

Strategy: validation

Validate before calling

def build_ordered_dict(*mappings):
    merged = []
    for m in mappings:
        merged.extend(m.items() if hasattr(m, 'items') else m)
    if len(mappings) > 1:
        return __import__('collections').OrderedDict(merged)  # merge manually, never pass >1 positional
    return __import__('collections').OrderedDict(*mappings)

Type guard

def is_single_positional_mapping(args):
    return len(args) <= 1 and (len(args) == 0 or hasattr(args[0], 'keys') or hasattr(args[0], '__iter__'))

Try / catch

try:
    od = OrderedDict(d1, d2)
except TypeError as e:
    if 'expected at most 1 arguments' in str(e):
        od = OrderedDict(list(d1.items()) + list(d2.items()))
    else:
        raise

Prevention

When it happens

Trigger: Calling OrderedDict(mapping1, mapping2) or OrderedDict(iterable, anyOtherArg) — i.e. two or more positional arguments — on this vendored backport (triggered internally when urllib3 or hosts code builds headers from multiple dicts positionally).

Common situations: Porting Python 3 dict-merge style code `OrderedDict(d1, **d2)` expecting update semantics; code written for Python 2.7 backports merging two header dicts; passing a default dict plus an override dict positionally.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/913c3058d721543b. Report an issue: GitHub.