{"record":{"id":"9a90ac69c8eb7f0c","repo":"arduino/Arduino","slug":"end-must-be-none-or-a-string","errorCode":null,"errorMessage":"end must be None or a string","messagePattern":"end must be None or a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/packages/six.py","lineNumber":356,"sourceCode":"        if fp is None:\n            return\n        def write(data):\n            if not isinstance(data, basestring):\n                data = str(data)\n            fp.write(data)\n        want_unicode = False\n        sep = kwargs.pop(\"sep\", None)\n        if sep is not None:\n            if isinstance(sep, unicode):\n                want_unicode = True\n            elif not isinstance(sep, str):\n                raise TypeError(\"sep must be None or a string\")\n        end = kwargs.pop(\"end\", None)\n        if end is not None:\n            if isinstance(end, unicode):\n                want_unicode = True\n            elif not isinstance(end, str):\n                raise TypeError(\"end must be None or a string\")\n        if kwargs:\n            raise TypeError(\"invalid keyword arguments to print()\")\n        if not want_unicode:\n            for arg in args:\n                if isinstance(arg, unicode):\n                    want_unicode = True\n                    break\n        if want_unicode:\n            newline = unicode(\"\\n\")\n            space = unicode(\" \")\n        else:\n            newline = \"\\n\"\n            space = \" \"\n        if sep is None:\n            sep = space\n        if end is None:\n            end = newline\n        for i, arg in enumerate(args):","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/i18n/python/requests/packages/urllib3/packages/six.py#L338-L374","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a string terminator: end='' or end='\\n'.","Coerce: end=str(value) before calling.","Omit end to use the default newline."],"exampleFix":"// before\nsix.print_('progress', end=i)\n// after\nsix.print_('progress', end=' ')","handlingStrategy":"validation","validationCode":"if end is not None and not isinstance(end, (str, unicode)):\n    end = str(end)","typeGuard":"def is_valid_end(end):\n    return end is None or isinstance(end, (str, unicode))","tryCatchPattern":"try:\n    six.print_(*args, end=end)\nexcept TypeError as e:\n    if 'end must be None or a string' in str(e):\n        six.print_(*args, end=str(end))\n    else:\n        raise","preventionTips":["Only pass str/unicode (or None) as end.","Use literal terminators like '' or '\\n' rather than computed values.","Audit kwargs dicts forwarded to print_ for non-string end values."],"tags":["python","six","typeerror","print"],"backgroundTag":"invalid-argument-value","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}