[Python-Dev] Oddity in AST for 3-argument slices (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Thu Aug 19 15:26:21 CEST 2010


On Thu, Aug 19, 2010 at 8:35 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

Nick Coghlan wrote:

Or else it's just an accident of implementation, since the AST doesn't actually need to distinguish those two cases. It doesn't seem to be an accident, because astforslice() goes out of its way to manufacture a Name node for the missing argument. It doesn't seem to significantly simplify the compiler either, because compilerslice() could just as easily treat it the same way as the other slice arguments and emit an instruction to load None if it's missing. So it's a mystery. Perhaps it made life easier for some earlier version of the compiler.

Ah, it's a 2.x-ism. The old compiler needed to know whether or not to try get/set/delslice (yes for x[:], no for x[::]). With those magic methods gone, that would make it obsolete in 3.x, so x[::] should probably just be changed to generate the same AST as x[:] now.

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list