arduino/Arduino · error · TypeError

end must be None or a string

Error message

end must be None or a string

What it means

six.print_ validates its end keyword exactly like sep: it must be None, str, or unicode. Supplying a non-string terminator (number, list, object) raises this TypeError, mirroring the built-in print() function's contract.

Source

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

        if fp is None:
            return
        def write(data):
            if not isinstance(data, basestring):
                data = str(data)
            fp.write(data)
        want_unicode = False
        sep = kwargs.pop("sep", None)
        if sep is not None:
            if isinstance(sep, unicode):
                want_unicode = True
            elif not isinstance(sep, str):
                raise TypeError("sep must be None or a string")
        end = kwargs.pop("end", None)
        if end is not None:
            if isinstance(end, unicode):
                want_unicode = True
            elif not isinstance(end, str):
                raise TypeError("end must be None or a string")
        if kwargs:
            raise TypeError("invalid keyword arguments to print()")
        if not want_unicode:
            for arg in args:
                if isinstance(arg, unicode):
                    want_unicode = True
                    break
        if want_unicode:
            newline = unicode("\n")
            space = unicode(" ")
        else:
            newline = "\n"
            space = " "
        if sep is None:
            sep = space
        if end is None:
            end = newline
        for i, arg in enumerate(args):

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Pass a string terminator: end='' or end='\n'.
  2. Coerce: end=str(value) before calling.
  3. Omit end to use the default newline.

Example fix

// before
six.print_('progress', end=i)
// after
six.print_('progress', end=' ')
Defensive patterns

Strategy: validation

Validate before calling

if end is not None and not isinstance(end, (str, unicode)):
    end = str(end)

Type guard

def is_valid_end(end):
    return end is None or isinstance(end, (str, unicode))

Try / catch

try:
    six.print_(*args, end=end)
except TypeError as e:
    if 'end must be None or a string' in str(e):
        six.print_(*args, end=str(end))
    else:
        raise

Prevention

When it happens

Trigger: six.print_('x', end=0); passing end=b'' (bytes on Python 2 is str, but other non-str objects fail); constructing end dynamically and getting a non-string type.

Common situations: Using numeric line counters or sentinel objects as terminators; Python 2/3 code sharing a constant where one branch yields a non-string; typos passing args positionally so a value lands in end via kwargs dict.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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