[issue12657] Cannot override JSON encoding of basic type subclasses
Stefan Champailler added the comment: I'm adding a scenario for this problem, a real life one, so it gives a bit more substance. I use SQLALchemy. I do queries with it which returns KeyedTuples (an SQLALchemy type). KeyedTuples inherits from tuple. KeyedTuples are, in principle, like NamedTuple. I want to transmit the result of my queries over json. Since KeyedTuple inherit from tuple, json can't serialize them. Of course one might say that that problem is outside the scope of json. But if so, it means we have to first convert KeyedTuples to dict and then pass the dict to json. That's alot of copies to do... This problem is rather big because it affects my whole API (close to a hundred of functions)... I've looked into the code and as noted above, one could replace 'isinstance(x,tuple)' with 'type(x) == tuple'. But without knowledge of how many people use the flexibility introduced by isinstance, it's dangerous. We could also change the nature of default and say that default is called before any type checking in json (so default is not a 'default' anymore). We could also duplicate the default functionnality (so a function called before any type checks and then a default called if all type checks fail). But for these two last cases, I guess the difficulty is : how do we know the pre-type 'default' was applied correctly ? Patching is not easy because, at least in my case, the C code path is taken = an easy patch (i.e. full python) would force me out of the C path which may be bad for performance (I didn't measure the difference between the 2 paths). I see this bug is old and not much commented, should we conclude that nobody cares ? That'd a good news since it'd mean a patch wouldn't hurt many people :-) -- nosy: +wiz21 versions: +Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12657] Cannot override JSON encoding of basic type subclasses
Stefan Champailler added the comment: Reading bugs a bit, I see this is quite related to : http://bugs.python.org/issue14886 stF -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12657 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602] windows console doesn't print or input Unicode
Stefan Champailler added the comment: Thank you all for your quick and good answers. This level of responsiveness is truly amazing. I've played a bit with IPython and it works just fine. I can type the eurosign drectly with Alt Gr - E (so I didn't enter a unicode code). So the bug is basically solved for me. But the python-repl behaviour still looks strange to me. So here's a successful IPython session : C:\PORT-STCA2\pl-PRIVATE\horsechcp 65001 Active code page: 65001 C:\PORT-STCA2\pl-PRIVATE\horseipython Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] Type copyright, credits or license for more information. IPython 2.2.0 -- An enhanced Interactive Python. ? - Introduction and overview of IPython's features. %quickref - Quick reference. help - Python's own help system. object? - Details about 'object', use 'object??' for extra details. In [1]: print('€') € In [2]: -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602] windows console doesn't print or input Unicode
Stefan Champailler added the comment: I don't know if this is 100% related, but here I go. Here's a session in a windows console (cmd.exe) : Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\stcchcp 65001 Active code page: 65001 C:\Users\stc\PORT-STCA2\opt\python3\python Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print '€' C:\Users\stc So basically, the python interpreters just quits without any message. Windows doesn't comply about python crashing though... Best regards, Stefan -- nosy: +wiz21 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602] windows console doesn't print or input Unicode
Stefan Champailler added the comment: In my previous comment, I've shown : print '€' which is not valid python 3.4.1 (don't why the interpreter didn't complaing though). So I tested again with missing parenthesis added : C:\PORT-STCA2\pl-PRIVATE\horsechcp 65001 Active code page: 65001 C:\PORT-STCA2\pl-PRIVATE\horsepython Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print(€) C:\PORT-STCA2\pl-PRIVATE\horseecho %PROCESSOR_IDENTIFIER% Intel64 Family 6 Model 42 Stepping 7, GenuineIntel Exactly the same behaviour. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1602] windows console doesn't print or input Unicode
Stefan Champailler added the comment: Dear Drekin, The crash you see is maybe not a crash at all. First it has nothing to do with printing, the problem is reading of your input line. I guessed that, but thanks for pointing out. So maybe Python REPL then thinks the input just ended and so standardly exits the interpreter. Yes. I have showed that because the line of code seemed perfectly valid and innocuous (I moved to Python3 because I *need* good unicode/encodings support). The answer from the REPL is, to me, very suprising. I would have expected a badly displayed character at least and a syntax error at worst. I consider myself quite aware of unicode issues but without any output from the repl, I'd have very hard times figuring out what went wrong, hence my bug report. So even though this might not qualify as the worse bug in Python, I'd say it is actually quite misleading. But see no complaint here, I'm very happy with Python in general. It's just that I thought I had to tell it to the dev team. Why are you using chcp 65001? I thought it'd help me with printing unicode (I tried CP437 but problem is the EURO sign is not there, and I *do* need eurosign :-)). But I'll readily admit I didn't read all the stuff about encoing issues on Windows console before trying. try my package `win_unicode_console`, which tries to solve the issues. I'll certainly do that. Thank you for your answer Stefan -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1602 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com