[issue8256] TypeError: bad argument type for built-in operation
STINNER Victor victor.stin...@haypocalc.com added the comment: This issue is directly related to issue #6697. The first problem is that the builtin input() function doesn't check that _PyUnicode_AsString() result is not NULL. The second problem is that io.StringIO().encoding is None. I don't understand why it is None whereas it uses utf8 (it calls TextIOWrapper constructor with encodings=utf8 and errors=strict). I will be difficult to write an unit test because the issue only occurs if stdin and stdout are TTY: input() calls PyOS_Readline(stdin, stdout, prompt). -- @gruszczy: You're patch is just a workaround, not the right fix. The problem should be fixed in input(), not in PyUnicode methods. _PyUnicode_AsString() expects an unicode argument, it should raise an error if the argument is None (and not return a magical value). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: Amaury, could you elaborate a little more on this? I am pretty new to all this and I would happily write the patch, if only you could give me some clue on how I should approach this. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Changes by Alexander Belopolsky belopol...@users.sourceforge.net: -- nosy: +belopolsky ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
R. David Murray rdmur...@bitdance.com added the comment: Victor, you've been dealing with Python's default encoding lately, care to render an opinion on the correct fix for this bug? @Filip: the patch will need a unit test, which will also help with assessing the validity of the fix. -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: I'll try to code a small test this evening. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: The patch is wrong: _PyUnicode_AsString(Py_None) should not return utf8! I suggest that since PyOS_Readline() write the prompt to stderr, the conversion uses the encoding of stderr. -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: Bump! Is there anything happening about this bug? Is my patch any good or should I try to work on something different? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: I have read, that I shouldn't directly use Py_FileSystemDefaultEncoding and rather use PyUnicode_GetDefaultEncoding, so I have changed the code a little. -- Added file: http://bugs.python.org/file16700/8256_3.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Changes by Filip Gruszczyński grusz...@gmail.com: Removed file: http://bugs.python.org/file16688/8256_1.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Changes by Filip Gruszczyński grusz...@gmail.com: Removed file: http://bugs.python.org/file16689/8256_2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: The problem occurs in line in bltinmodule.c: po = PyUnicode_AsEncodedString(stringpo, _PyUnicode_AsString(stdout_encoding), NULL); Where _PyUnicode_AsString returns NULL, since stdout_encoding is Py_None and that won't pass PyUnicode_Check in _PyUnicode_AsStringAndSize. To what object can _PyUnicode_AsString be turned and then passed to _PyUnicode_AsStringAndSize? Is there some default 'utf-8' encoding object? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
R. David Murray rdmur...@bitdance.com added the comment: Whatever the solution to this issue is, it certainly looks like a bug that the return value of that function isn't being checked for errors. -- nosy: +r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: I have written a small patch, that solves the problem, but is disgusting. Could anyone tell me, how I can get some default encoding from Python internals (I have no idea where to look) and return it inside _PyUnicode_AsStringAndSize? Anyway, now when the error happens inside input, it raises an Exception properly. So now I only need to know, how to correct the bug in an elegant fashion. -- keywords: +patch Added file: http://bugs.python.org/file16688/8256_1.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: Ok, I have found Py_FileDefaultSystemEncoding and use it, however I had to cast it to (char *), because it's a const char *. Maybe I could do it better? -- Added file: http://bugs.python.org/file16689/8256_2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
New submission from Bruce Frederiksen dangy...@gmail.com: I'm getting a TypeError: bad argument type for built-in operation on a print() with no arguments. This seems to be a problem in both 3.1 and 3.1.2 (haven't tried 3.1.1). I've narrowed the problem down in a very small demo program that you can run to reproduce the bug. Just do python3.1 bug.py and hit ENTER at the prompt:. Removing the doctest call (and calling foo directly) doesn't get the error. Also removing the input call (and leaving the doctest call in) doesn't get the error. The startup banner on my python3.1 is: Python 3.1.2 (r312:79147, Mar 26 2010, 16:55:44) [GCC 4.3.3] on linux2 I compiled python 3.1.2 with ./configure, make, make altinstall without any options. I'm running ubuntu 9.04 with the 2.6.28-18-generic (32-bit) kernel. -- components: IO, Interpreter Core, Library (Lib) files: bug.py messages: 101874 nosy: dangyogi severity: normal status: open title: TypeError: bad argument type for built-in operation type: behavior versions: Python 3.1 Added file: http://bugs.python.org/file16681/bug.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Florent Xicluna florent.xicl...@gmail.com added the comment: Confirmed. There's something wrong around the doctest._SpoofOut class. This script triggers the same bug (both 3.x and 3.1). Output: $ ./python issue8256_case.py prompt: Traceback (most recent call last): File issue8256_case.py, line 13, in module foo() File issue8256_case.py, line 7, in foo print() TypeError: bad argument type for built-in operation -- components: -Interpreter Core nosy: +flox priority: - normal stage: - test needed versions: +Python 3.2 Added file: http://bugs.python.org/file16682/issue8256_case.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Filip Gruszczyński grusz...@gmail.com added the comment: The bug is triggered by input, not by print. The exact place is _PyUnicode_AsStringAndSize, where unicode check happens. Then print checks PyError_Occured and catches this error. Either this error should not be raised or should be cleared input finishes. I'd love to provide a patch, but I have no idea, what should be corrected and how. If some would tutor me a little, I would be very happy to learn and code this. -- nosy: +gruszczy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Changes by Florent Xicluna florent.xicl...@gmail.com: Removed file: http://bugs.python.org/file16682/issue8256_case.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8256] TypeError: bad argument type for built-in operation
Florent Xicluna florent.xicl...@gmail.com added the comment: Right. It does not involve doctest. # import io, sys original_stdout = sys.stdout try: sys.stdout = io.StringIO() input(prompt:) print() finally: sys.stdout = original_stdout -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8256 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
bad argument type for built-in operation
Hello, I've the traceback: Traceback (most recent call last): File visualizer.py, line 8, in ? main() File visualizer.py, line 5, in main g = GraphCreator(f) File /home/florian/visualizer/GraphCreator.py, line 13, in __init__ self.conf = ConfigReader(config) File /home/florian/visualizer/ConfigReader.py, line 53, in __init__ graph.sourceReader = CSVReader(filename, firstline, delimiter) File /home/florian/visualizer/ConfigReader.py, line 13, in __init__ self.reader = csv.reader(f, delimiter=Adelimiter) TypeError: bad argument type for built-in operation f ist file object, Adelimiter is ,. What is wrong there? Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list
RE: bad argument type for built-in operation
Florian Lindner wrote: Traceback (most recent call last): File visualizer.py, line 8, in ? main() File visualizer.py, line 5, in main g = GraphCreator(f) File /home/florian/visualizer/GraphCreator.py, line 13, in __init__ self.conf = ConfigReader(config) File /home/florian/visualizer/ConfigReader.py, line 53, in __init__ graph.sourceReader = CSVReader(filename, firstline, delimiter) File /home/florian/visualizer/ConfigReader.py, line 13, in __init__ self.reader = csv.reader(f, delimiter=Adelimiter) TypeError: bad argument type for built-in operation f ist file object, Adelimiter is ,. What is wrong there? Lack of code. I'd start looking very carefully as to whether `f` really is a file object. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
bad argument type for built-in operation
Hello, I've got a nasty bug and no idea to deal with : here is the method : method def denormer(self, var) : denorme un vecteur d'entree try: #a = map(self.decerner, self.param, var) #a = [self.decerner(x, y) for x, y in map(None, self.param, var)] a = [] print 'in', None, self.param, var, len(self.param), len(var), str(self.decerner) #return map(undoc, self.param, var) print map(None, var) print map(None, self.param) #print zip(var, var) #print zip(self.param, self.param) #print map(lambda x, y: (x,y), self.param, var) #print zip(self.param, var) b = [] print '$', ii = range(len(var)) print ii, '$', for i in ii : print '%', b.append((self.param[i], var[i])) print b, '/', print '$', print b for x,y in b : print x, y z = undoc(x, y) print z a.append(z) except TypeError, c : print 'E', str(self.decerner), self.param, var print 'E2', str(c) raise return a /method in fact the method was initially reduce to method return map(self.decerner, self.param, var) /method all the commented line produced the same exception raised this method unnormalize an input vector (var) and the trace trace in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847, 0.87787941093093491] 2 2 function undo at 0x81ff94c [0.1385039192456847, 0.87787941093093491] [(-2.0, 2.0), (-2.0, 2.0)] $ [0, 1] $ % [((-2.0, 2.0), 0.1385039192456847)] / % [((-2.0, 2.0), 0.1385039192456847), ((-2.0, 2.0), 0.87787941093093491)] / $ [((-2.0, 2.0), 0.1385039192456847), ((-2.0, 2.0), 0.87787941093093491)] (-2.0, 2.0) 0.138503919246 % 0.277007838491 (-2.0, 2.0) 0.877879410931 % 1.75575882186 in None [(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943, 0.74880175070169164] 2 2 function undo at 0x81ff94c [0.38111874838950943, 0.74880175070169164] [(-2.0, 2.0), (-2.0, 2.0)] $ [0, 1] $ % [((-2.0, 2.0), 0.38111874838950943)] / % [((-2.0, 2.0), 0.38111874838950943), ((-2.0, 2.0), 0.74880175070169164)] / E function undo at 0x81ff94c [(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943, 0.74880175070169164] E2 bad argument type for built-in operation [...] /trace the first call of the methode succeed all following call failed. I've got different scenario which call this low level methode, many succeed, some failed this way. what's happened ? If someone got an idea ? what can raise this exception ? My program is written partially in python and partially in C. the top level is in python which call a C optimisation routine which use a callback (PyObject_CallMethod) to evaluate the cost in python again. -- http://mail.python.org/mailman/listinfo/python-list
Re: bad argument type for built-in operation
Gilles Arnaud wrote: Hello, I've got a nasty bug and no idea to deal with : here is the method : Big snip. The Python code is unlikely to be your problem. and the trace trace in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847, 0.87787941093093491] 2 2 function undo at 0x81ff94c [0.1385039192456847, 0.87787941093093491] That's a very mangled trace! the first call of the methode succeed all following call failed. So the first call is leaving a bomb behind. I've got different scenario which call this low level methode, many succeed, some failed this way. what's happened ? If someone got an idea ? what can raise this exception ? At this stage, without the benefit of look-ahead, one could only blame gamma rays or pointy-eared aliens :-) My program is written partially in python and partially in C. the top level is in python which call a C optimisation routine which use a callback (PyObject_CallMethod) to evaluate the cost in python again. Aha! *Now* you tell us. *You* have denormalised the stack. Read your C code carefully. Use a debugger, or put some printf() in it. With PyObject_CallMethod, do the format descriptors and the arguments match? Are you testing the returned value for NULL and acting accordingly? Is the called-from-C Python method ever executed? Try putting a print statement (that shows the args) at the top. More generally, are you testing the returned value from each and every C API call? Are you testing for the correct error value (some return NULL, some -1, ...)? Are you doing the right thing on error? A catalogue of the different ways of messing things up using C would take forever to write. If you can't find your problem, post the code, either on the newsgroup or as a web page. Hope this helps, John -- http://mail.python.org/mailman/listinfo/python-list