You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Agreed that this should be supported. Probably easy to fix since it really only needs a Py_None check that uses PY_SSIZE_T_MAX if true (or 0 for None in the first slice index), and use the current integer conversion code otherwise. PR welcome.
First, add tests to tests/run/typed_slice.pyx that do not use C integer variables as slice arguments. Run them with python runtests.py -vv --debug typed_slice (or, more slicing tests with just slice instead of typed_slice). Look at the generated C code under TEST_TMP/run/ for the test that you added.
Then, the 2-element slicing case is handled in SliceIndexNode.analyse_types() in ExprNodes.py. Near the end, you find two coercions of start and stop to C integer types for the case that the result type of the slicing node is not just an arbitrary object (py_object_type) but a known object type. Each of them needs to be replaced with a CondExprNode that checks for None (-> PrimaryCmpNode) and then either uses the coerced value as before, or a constant integer value (0 or PY_SSIZE_T_MAX). Look at Parsing.py to see how nodes are created. You can dump the current syntax subtree at any time with print(self.dump()).
Hey @maxkrivich - I had started work towards remedying this issue, but haven't worked on it in several days, and am more than willing to pass it off to someone with more free time. If you'd like, please feel free to leverage the handful of failing tests I have on my forked branch at master...cjgibson:2508-slicing-fixes.
Ah, what a nice suite of tests. That should help a lot in getting this right.
I would still split up the doctests with the double/triple nested loops (at least by slice type) to keep things readable. And use print() in it to also show the start and stop indices. Otherwise, it's entirely unclear where to look if one of the examples starts failing.
Hahah, @scoder - that's a realization I came to a little late. Had I started with the fully nested case first, I hope I would have resisted the urge to make the tests so large. I'll make time this weekend to trim down the number of tested cases to the minimal set required to cover the usual troublemakers (empty slice, oversized bounds, etc.) and include the requested verbosity.