[Snek] [keith-packard/snek] c03d6b: Fix up is vs == to match Python3 semantics

Keith Packard noreply at github.com
Thu Feb 7 00:37:12 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/keith-packard/snek
  Commit: c03d6bb62e5180846340df9166b4cee51ff5b51c
      https://github.com/keith-packard/snek/commit/c03d6bb62e5180846340df9166b4cee51ff5b51c
  Author: Keith Packard <keithp at keithp.com>
  Date:   2019-02-07 (Thu, 07 Feb 2019)

  Changed paths:
    M snek-list.c
    M snek-poly.c
    M snek.h
    M test/equal_is.py

  Log Message:
  -----------
  Fix up is vs == to match Python3 semantics

The python3 compiler does constant folding so that when it sees the
same constant in source code. This confused me when I was doing some
simple tests with the REPL where

	>>> (1,2) is (1,2)
	True

but

	>>> a = (1,2)
	>>> b = (1,2)
	>>> a is b
	False

Stick the latter in a file and it *also* gets True as the compiler
does whole-file constant folding.

So, here's my understanding of 'is' vs '==':

is:

 Tuples and lists: object comparison, not contents
 Strings: content comparisons

==

 Content comparisons, using == on each element of the list/tuple, so
 it recurses down the data structure.

I've fixed the test to force Python3 to generate unique tuples even
when compiled from a single file so that the results match snek, which
doesn't manage to share tuples.

Signed-off-by: Keith Packard <keithp at keithp.com>


  Commit: b19fdd3e122d310b123d40242c0eb3f5bd4c49d2
      https://github.com/keith-packard/snek/commit/b19fdd3e122d310b123d40242c0eb3f5bd4c49d2
  Author: Keith Packard <keithp at keithp.com>
  Date:   2019-02-07 (Thu, 07 Feb 2019)

  Changed paths:
    M Makefile
    M test/Makefile
    M test/equal_is.py
    M test/global.py

  Log Message:
  -----------
  test: Make reporting easier to scan for failures.

Signed-off-by: Keith Packard <keithp at keithp.com>


Compare: https://github.com/keith-packard/snek/compare/6de3d64cfbfe...b19fdd3e122d


More information about the Snek mailing list