Status: Accepted
Owner: nicolas.pourcelot
CC: Vinzent.Steinberg,  asmeurer,  smichr
Labels: Type-Defect Priority-Medium

New issue 2125 by nicolas.pourcelot: Using Integers as python slices.
http://code.google.com/p/sympy/issues/detail?id=2125

I'd like to be able to use sympy Integers everywhere python integers are allowed, and so, to implement the following:

In [1]: a = Integer(2)

In [2]: "hello"[a:]
Out[2]: llo

For now, this raises an error:

"hello"[Integer(2):]
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method

However, adding an __index__ method to Integer makes the following work:

In [4]: a=Integer(2)

In [5]: a*'1'
Out[5]: 11

And there is a test in sympy/core/tests/test_expr.py preventing this behavior:

# basic sympy objects
basic_objs = [
    Rational(2),
    Real("1.3"),
    x,
    y,
    pow(x,y)*y,
]

def test_basic_nostr():
    for obj in basic_objs:
        for op in ['+','-','*','/','**']:
            raises(TypeError, "obj %s '1'" % op)


Why shouldn't that be allowed ?

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to