Re: [pypy-dev] [sympy] Re: sympy tests: pypy vs cpython incompatibilities

On Sat, Oct 11, 2008 at 8:13 PM, didier deshommes <dfdeshom@gmail.com> wrote:
On Sat, Oct 11, 2008 at 1:50 PM, Ondrej Certik <ondrej@certik.cz> wrote:
as soon as someone realizes that in CPython it is possible to speed up iteration over strings by creating a stringiterator type, then CPython will grow a 'str.__iter__' as well, and the same infinite recursion will occur in sympy...
A cleaner way to say "is x iterable?" would be to try to call iter(x) and see if it raises TypeError or not.
Indeed, thanks very much for the tip. We'll fix that, that's definitely something that should be fixed in sympy, I created a new issue for that:
Hi, I've faced the same problem and checking if x has the __getitem__ attribute has worked for me. The rationale being that any iterable has a way to access its individual items.
Thanks Didier for the tip. Both iter("p") and "p".__getitem__ behaves the same in both python and pypy. But "p".__iter__ behaves differently and our code assumed that "p" is not iterable, so I just implemented a function: http://code.google.com/p/sympy/issues/detail?id=1153#c1 +def is_iterable(x): + try: + iter(x) + if isinstance(x, str) and len(x) == 1: + return False + return True + except TypeError: + return False Which fixes the problem above. Unfortunately, then there are other unrelated problems. Armin, is there some way to tell pypy-c to stop on ctrl-C? I am getting hangups and the only way out is to kill the pypy-c program. It'd be much more convenient if I could just do ctrl-C and it would print the stacktrace. I'll be continuing porting sympy to pypy some other time, so anyone feel free to take over it. You just need to apply the patch in the issue 1153 and then try to make all tests to pass. Thanks, Ondrej

Hi Ondrej, On Sat, Oct 11, 2008 at 11:42:47PM +0200, Ondrej Certik wrote:
+def is_iterable(x): + try: + iter(x) + if isinstance(x, str) and len(x) == 1: + return False + return True + except TypeError: + return False
I don't see why there is a check for len(x); the same difference exists for strings of any length, not just characters.
Armin, is there some way to tell pypy-c to stop on ctrl-C? I am getting hangups and the only way out is to kill the pypy-c program. It'd be much more convenient if I could just do ctrl-C and it would print the stacktrace.
That's what it should do. Do you have a way to reproduce the problem? Just running the sympy tests with the above patch? A bientot, Armin
participants (2)
-
Armin Rigo
-
Ondrej Certik