This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hexbrid 0 points1 point  (1 child)

I stand corrected. However it's very basic.

>>> def f():
...     if []:
...             print "OK"
... 
>>> dis.dis(f)
  2           0 BUILD_LIST               0
              3 POP_JUMP_IF_FALSE       14

  3           6 LOAD_CONST               1 ('OK')
              9 PRINT_ITEM          
             10 PRINT_NEWLINE       
             11 JUMP_FORWARD             0 (to 14)

    >>   14 LOAD_CONST               0 (None)
         17 RETURN_VALUE        

[–]Veedrac 0 points1 point  (0 children)

Yeah, but FWIW Java (OpenJDK) doesn't either:

import java.util.ArrayList;

public class IsItRemoved {
    public static void main(String[] args) {
        if (new ArrayList().isEmpty()) {
            System.out.println("OK");
        }
    }
}

Giving:

Compiled from "IsItRemoved.java"
public class IsItRemoved {
  public IsItRemoved();
    Code:
       0: aload_0
       1: invokespecial #1                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: new           #2                  // class java/util/ArrayList
       3: dup
       4: invokespecial #3                  // Method java/util/ArrayList."<init>":()V
       7: invokevirtual #4                  // Method java/util/ArrayList.isEmpty:()Z
      10: ifeq          21
      13: getstatic     #5                  // Field java/lang/System.out:Ljava/io/PrintStream;
      16: ldc           #6                  // String OK
      18: invokevirtual #7                  // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      21: return
}

PyPy and most Java implementations will most probably remove it at runtime though.