arduino/Arduino · error · TypeError

update() takes at most 2 positional arguments (%d given)

Error message

update() takes at most 2 positional arguments (%d given)

What it means

The vendored OrderedDict.update() is defined with *args (unbound-style) and enforces that at most 2 positional arguments are passed: the implicit self plus one mapping/iterable source. Passing 3 or more positional arguments (e.g. two source mappings) exceeds that and raises this TypeError with the actual count interpolated.

Source

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

        for k in self:
            yield self[k]

    def iteritems(self):
        'od.iteritems -> an iterator over the (key, value) items in od'
        for k in self:
            yield (k, self[k])

    def update(*args, **kwds):
        '''od.update(E, **F) -> None.  Update od from dict/iterable E and F.

        If E is a dict instance, does:           for k in E: od[k] = E[k]
        If E has a .keys() method, does:         for k in E.keys(): od[k] = E[k]
        Or if E is an iterable of items, does:   for k, v in E: od[k] = v
        In either case, this is followed by:     for k, v in F.items(): od[k] = v

        '''
        if len(args) > 2:
            raise TypeError('update() takes at most 2 positional '
                            'arguments (%d given)' % (len(args),))
        elif not args:
            raise TypeError('update() takes at least 1 argument (0 given)')
        self = args[0]
        # Make progressively weaker assumptions about "other"
        other = ()
        if len(args) == 2:
            other = args[1]
        if isinstance(other, dict):
            for key in other:
                self[key] = other[key]
        elif hasattr(other, 'keys'):
            for key in other.keys():
                self[key] = other[key]
        else:
            for key, value in other:
                self[key] = value
        for key, value in kwds.items():

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Update sequentially: od.update(a); od.update(b).
  2. Merge into a temporary dict first: od.update({**a, **b}) (or dict(a, **b) on Py2).
  3. Use od.update(itertools.chain(a.items(), b.items())) since an iterable of pairs is accepted.

Example fix

// before
od.update(defaults, overrides)
// after
od.update(defaults)
od.update(overrides)
Defensive patterns

Strategy: validation

Validate before calling

# inspect before call
args = (defaults, overrides)
assert 0 < len(args) <= 1, 'this OrderedDict.update takes at most self + 1 source'

Try / catch

try:
    od.update(a, b)
except TypeError as e:
    if 'at most 2 positional' in str(e):
        od.update(a); od.update(b)
    else:
        raise

Prevention

When it happens

Trigger: Calling od.update(dict_a, dict_b) to merge two mappings in one call, or any other call passing 3+ positional arguments to update(); six.moves-era Py2.6 backport of OrderedDict does not support multi-source update like dict.update in later Pythons.

Common situations: Migrating code written against Python 3.5+ dict.update(a, **b) multi-source semantics onto this vendored backport; chaining defaults and overrides in one update call.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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